#33767: Ordering by F-expression resolving to a number returns wrong results
-------------------------------------+-------------------------------------
Reporter: Florian | Owner: nobody
Apolloner |
Type: Bug | Status: new
Component: Database | Version: dev
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{
Article.objects.annotate(test=Value(42)).order_by(F("test").asc())
}}}
yields
{{{
Traceback (most recent call last):
File "/home/florian/sources/django.git/django/db/backends/utils.py",
line 89, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.InvalidColumnReference: ORDER BY position 42 is not in
select list
LINE 1: ...e", 42 AS "test" FROM "ordering_article" ORDER BY 42 ASC LIM...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/florian/sources/django.git/tests/ordering/tests.py", line
485, in test_order_by_f_expression_alias
print(qs)
File "/home/florian/sources/django.git/django/db/models/query.py", line
370, in __repr__
data = list(self[: REPR_OUTPUT_SIZE + 1])
File "/home/florian/sources/django.git/django/db/models/query.py", line
376, in __len__
self._fetch_all()
File "/home/florian/sources/django.git/django/db/models/query.py", line
1841, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/florian/sources/django.git/django/db/models/query.py", line
87, in __iter__
results = compiler.execute_sql(
File
"/home/florian/sources/django.git/django/db/models/sql/compiler.py", line
1401, in execute_sql
cursor.execute(sql, params)
File "/home/florian/sources/django.git/django/db/backends/utils.py",
line 103, in execute
return super().execute(sql, params)
File "/home/florian/sources/django.git/django/db/backends/utils.py",
line 67, in execute
return self._execute_with_wrappers(
File "/home/florian/sources/django.git/django/db/backends/utils.py",
line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/florian/sources/django.git/django/db/backends/utils.py",
line 84, in _execute
with self.db.wrap_database_errors:
File "/home/florian/sources/django.git/django/db/utils.py", line 91, in
__exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/florian/sources/django.git/django/db/backends/utils.py",
line 89, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: ORDER BY position 42 is not in select
list
LINE 1: ...e", 42 AS "test" FROM "ordering_article" ORDER BY 42 ASC LIM...
}}}
the issue here is that the `F` expression is not resolved to a `Ref` like
it should be
--
Ticket URL: <https://code.djangoproject.com/ticket/33767>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701813491e0a3-53934de5-bec2-46aa-a628-7383d067a8d9-000000%40eu-central-1.amazonses.com.