Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#19087 closed Bug (fixed)

Annotate() followed by exclude() raises an exception

Reported by: ivan_virabyan Owned by: akaariai
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 3 years ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to akaariai
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

  • Resolution set to fixed
  • Status changed from new to closed

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 3 years ago by akaariai

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

comment:4 Changed 3 years ago by ivan_virabyan

works great, thanks!

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