Opened 6 years ago

Closed 6 years ago

Last modified 6 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: master
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


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/", 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/, whereas in django 1.4 it doesn't

If I swap exclude() and annotate(), it works:

Change History (4)

comment:1 Changed 6 years ago by Anssi Kääriäinen

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

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

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:

Thanks to Ivan Virabyan for the report.

comment:3 Changed 6 years ago by Anssi Kääriäinen

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

comment:4 Changed 6 years ago by Ivan Virabyan

works great, thanks!

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