Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19087 closed Bug (fixed)

Annotate() followed by exclude() raises an exception

Reported by: Ivan Virabyan Owned by: Anssi Kääriäinen
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

class Post(models.Model):
     author = models.ForeignKey(User)

>>>print Post.objects.values('author').annotate(n=Count('pk')).exclude(author=1).query
  ...
  File "django/django/db/backends/sqlite3/base.py", line 157, in quote_name
    if name.startswith('"') and name.endswith('"'):
AttributeError: 'NoneType' object has no attribute 'startswith'

This works fine in django 1.4

I tried to investigate the bug, and found that it tries to join the user table (db/models/sql/query.py:1190), whereas in django 1.4 it doesn't

If I swap exclude() and annotate(), it works:
Post.objects.values('author').exclude(author=1).annotate(n=Count('pk'))

Change History (4)

comment:1 by Anssi Kääriäinen, 12 years ago

Owner: changed from nobody to Anssi Kääriäinen
Triage Stage: UnreviewedAccepted

comment:2 by Anssi Kääriäinen <akaariai@…>, 12 years ago

Resolution: fixed
Status: newclosed

In a62d53c03252bdf82b21b64874efe053160cbdb7:

Fixed #19087 -- Ensured query's base table is never LOUTER joined

This fixes a regression created by join promotion logic refactoring:
01b9c3d5193fe61b82ae8b26242a13fdec22f211

Thanks to Ivan Virabyan for the report.

comment:3 by Anssi Kääriäinen, 12 years ago

I am 99% sure I found the reason for this regression. Could you verify that the bug is fixed for you?

comment:4 by Ivan Virabyan, 12 years ago

works great, thanks!

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