#32636: QuerySet.values()/values_list() crashes on a combined queryset ordered 
by
"extra" select.
-------------------------------------+-------------------------------------
               Reporter:  Mariusz    |          Owner:  nobody
  Felisiak                           |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |       Keywords:  queryset combined
               Severity:  Normal     |  union difference intersection extra
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 `QuerySet.values()`/`values_list()` crashed on a combined queryset ordered
 by "extra" select, e.g.
 {{{
     def
 
test_union_multiple_models_with_values_list_and_order_by_extra_select_different_fields(self):
         from .models import Celebrity
         reserved_name = ReservedName.objects.create(name='rn1', order=0)
         celebrity = Celebrity.objects.create(name='John Doe')
         qs1 = Celebrity.objects.extra(select={'extra_name':
 'greatest_fan_id'})
         qs2 = ReservedName.objects.extra(select={'extra_name': 'name'})
         self.assertSequenceEqual(
             qs1.union(qs2).order_by('extra_name').values_list('pk',
 flat=True),
             [reserved_name.pk, celebrity.pk],
         )
 }}}

 tries to execute:

 {{{
 SELECT "queries_celebrity"."id", (greatest_fan_id) AS "__orderbycol2" FROM
 "queries_celebrity"
 UNION
 SELECT "queries_reservedname"."id", (greatest_fan_id) AS "__orderbycol2"
 FROM "queries_reservedname"
 ORDER BY (2)
 }}}

 and crashes with:

 {{{
 ======================================================================
 ERROR:
 
test_union_multiple_models_with_values_list_and_order_by_extra_select_different_fields
 (queries.test_qs_combinators.QuerySetSetOperationTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "django/django/db/backends/utils.py", line 84, in _execute
     return self.cursor.execute(sql, params)
   File "django/django/db/backends/sqlite3/base.py", line 416, in execute
     return Database.Cursor.execute(self, query, params)
 sqlite3.OperationalError: no such column: greatest_fan_id
 }}}

 It's related with #32627 but it's not a regression in
 464a4c0c59277056b5d3c1132ac1b4c6085aee08. It crashes in Django 3.1.X with:
 {{{
   File "django/django/db/models/sql/query.py", line 1912, in add_fields
     join_info = self.setup_joins(name.split(LOOKUP_SEP), opts, alias,
 allow_many=allow_m2m)
 AttributeError: 'NoneType' object has no attribute 'split'
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32636>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.2f9badd4c21360d4a58032bf46424fdd%40djangoproject.com.

Reply via email to