Skip to content

Commit

Permalink
Merge pull request #90 from Mogost/deferred-loading
Browse files Browse the repository at this point in the history
Fix deferred loading
  • Loading branch information
millerdev authored Apr 29, 2024
2 parents 88843ef + 42d29f7 commit 3d4fffe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions django_cte/cte.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def queryset(self):
query = CTEQuery(cte_query.model)
query.join(BaseTable(self.name, None))
query.default_cols = cte_query.default_cols
query.deferred_loading = cte_query.deferred_loading
if cte_query.annotations:
for alias, value in cte_query.annotations.items():
col = CTEColumnRef(alias, self.name, value.output_field)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@ def test_cte_queryset_with_custom_queryset(self):
('venus', 22, 'sun'),
('venus', 23, 'sun'),
])

def test_cte_queryset_with_deferred_loading(self):
cte = With(
OrderCustomManagerNQuery.objects.order_by("id").only("id")[:1]
)
orders = cte.queryset().with_cte(cte)
print(orders.query)

self.assertEqual([x.id for x in orders], [1])

0 comments on commit 3d4fffe

Please sign in to comment.