Skip to content

Commit 1e9ba4f

Browse files
authored
fix: TypeError when sorting by a RawSQL (#1788)
1 parent 3d18d03 commit 1e9ba4f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/test_queryset.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ async def test_annotate_order_expression(self):
575575
)
576576
self.assertEqual(data[0] + 1, data[1])
577577

578+
async def test_annotate_order_rawsql(self):
579+
qs = IntFields.annotate(idp=RawSQL("id+1")).order_by("-idp")
580+
data = await qs.first().values_list("id", "idp")
581+
self.assertEqual(data[0] + 1, data[1])
582+
578583
async def test_annotate_expression_filter(self):
579584
count = await IntFields.annotate(intnum1=F("intnum") + 1).filter(intnum1__gt=30).count()
580585
self.assertEqual(count, 23)

tortoise/queryset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def resolve_ordering(
230230
)
231231
elif field_name in annotations:
232232
if isinstance(annotation := annotations[field_name], Term):
233-
term = annotations
233+
term: Term = annotation
234234
else:
235235
annotation_info = annotation.resolve(
236236
ResolveContext(

0 commit comments

Comments
 (0)