File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 47
47
exclude :
48
48
- {python: '3.9', django: 'Django~=5.1.0'}
49
49
- {python: '3.9', django: 'Django~=5.2.0'}
50
+ env :
51
+ allowed_python_failure : ' 3.14'
50
52
services :
51
53
postgres :
52
54
image : postgres:latest
83
85
"PORT":"5432"
84
86
}
85
87
run : .venv/bin/pytest -v
88
+ continue-on-error : ${{ matrix.python == env.allowed_python_failure }}
86
89
- name : Check style
87
90
run : .venv/bin/ruff check
Original file line number Diff line number Diff line change @@ -113,8 +113,7 @@ def queryset(self):
113
113
qs ._iterable_class = ValuesIterable
114
114
for alias in getattr (cte_query , "selected" , None ) or ():
115
115
if alias not in cte_query .annotations :
116
- field = cte_query .resolve_ref (alias ).output_field
117
- col = CTEColumnRef (alias , self .name , field )
116
+ col = Ref (alias , cte_query .resolve_ref (alias ))
118
117
query .add_annotation (col , alias )
119
118
if cte_query .annotations :
120
119
for alias , value in cte_query .annotations .items ():
@@ -128,7 +127,7 @@ def queryset(self):
128
127
def _resolve_ref (self , name ):
129
128
selected = getattr (self .query , "selected" , None )
130
129
if selected and name in selected and name not in self .query .annotations :
131
- return Ref (name , self .query )
130
+ return Ref (name , self .query . resolve_ref ( name ) )
132
131
return self .query .resolve_ref (name )
133
132
134
133
Original file line number Diff line number Diff line change @@ -640,3 +640,36 @@ def test_cte_select_pk(self):
640
640
{'pk' : 11 },
641
641
{'pk' : 12 },
642
642
])
643
+
644
+ def test_django52_resolve_ref_regression (self ):
645
+ cte = With (
646
+ Order .objects .annotate (
647
+ pnt_id = F ("region__parent_id" ),
648
+ region_name = F ("region__name" ),
649
+ ).values (
650
+ # important: more than one query.select field
651
+ "region_id" ,
652
+ "amount" ,
653
+ # important: more than one query.annotations field
654
+ "pnt_id" ,
655
+ "region_name" ,
656
+ )
657
+ )
658
+ qs = (
659
+ cte .queryset ()
660
+ .with_cte (cte )
661
+ .values (
662
+ amt = cte .col .amount ,
663
+ pnt_id = cte .col .pnt_id ,
664
+ region_name = cte .col .region_name ,
665
+ )
666
+ .filter (region_id = "earth" )
667
+ .order_by ("amount" )
668
+ )
669
+ print (qs .query )
670
+ self .assertEqual (list (qs ), [
671
+ {'amt' : 30 , 'region_name' : 'earth' , 'pnt_id' : 'sun' },
672
+ {'amt' : 31 , 'region_name' : 'earth' , 'pnt_id' : 'sun' },
673
+ {'amt' : 32 , 'region_name' : 'earth' , 'pnt_id' : 'sun' },
674
+ {'amt' : 33 , 'region_name' : 'earth' , 'pnt_id' : 'sun' },
675
+ ])
You can’t perform that action at this time.
0 commit comments