Skip to content

Commit

Permalink
fix: TypeError when sorting by a RawSQL (#1788)
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng authored Nov 25, 2024
1 parent 3d18d03 commit 1e9ba4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/test_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ async def test_annotate_order_expression(self):
)
self.assertEqual(data[0] + 1, data[1])

async def test_annotate_order_rawsql(self):
qs = IntFields.annotate(idp=RawSQL("id+1")).order_by("-idp")
data = await qs.first().values_list("id", "idp")
self.assertEqual(data[0] + 1, data[1])

async def test_annotate_expression_filter(self):
count = await IntFields.annotate(intnum1=F("intnum") + 1).filter(intnum1__gt=30).count()
self.assertEqual(count, 23)
Expand Down
2 changes: 1 addition & 1 deletion tortoise/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def resolve_ordering(
)
elif field_name in annotations:
if isinstance(annotation := annotations[field_name], Term):
term = annotations
term: Term = annotation
else:
annotation_info = annotation.resolve(
ResolveContext(
Expand Down

0 comments on commit 1e9ba4f

Please sign in to comment.