Opened 4 years ago

Last modified 4 years ago

#31496 closed Bug

When using 'annotate', 'union', 'order_by('annotate_field')' and 'values' at the same time, error occurred — at Initial Version

Reported by: GardenLee Owned by: nobody
Component: Database layer (models, ORM) Version: 3.0
Severity: Normal Keywords:
Cc: Hasan Ramezani, David Wobrock Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When i tried query with 'annotate', 'union', 'order_by('annotate_field')' and 'values' at the same time, i got AttributeError('NoneType' object has no attribute 'split')

ex)
# 1. make 2 query_set
qs1 = Foo.objects.annotate(bar_val=Value(1, output_field=IntegerField())).filter(bar=False)
qs2 = Foo.objects.annotate(bar_val=Value(2, output_field=IntegerField())).filter(bar=True)

# 2. union
qs3 = q1.union(q2)

# 3. order_by annotate field
qs4 = q3.order_by('bar_val')

# 4. get values
q4.values('id')

In this case, I confirmed ('id', None) tuple passed by compiler.query.set_values() in django/db/models/sql/compiler.py

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top