#31496: Combined queryset crash when chaining `values()` after `order_by()` with
annotated constantants.
-------------------------------------+-------------------------------------
     Reporter:  GardenLee            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

 I take a look and here is my understanding:

 In this case, when we order queryset by annotated value(`bar_val`) the
 
[https://github.com/django/django/blob/060d9d4229c436c44cf8e3a301f34c4b1f9f6c85/django/db/models/sql/compiler.py#L374
 src] variable,  has type `<class
 'django.db.models.functions.comparison.Cast'>` and `src.output_field.name
 is None`.
 So,
 
[https://github.com/django/django/blob/060d9d4229c436c44cf8e3a301f34c4b1f9f6c85/django/db/models/sql/query.py#L1832
 add_select_col function] adds `None` to `values_select`.

 we should somehow add `bar_val` to the `values_select`.

 @felixxm, If you have any workaround, I can prepare a patch.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31496#comment:2>
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/064.83fa50379539ca4ad894fa168ee50591%40djangoproject.com.

Reply via email to