Code

Opened 21 months ago

Closed 21 months ago

Last modified 21 months 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

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'))

Attachments (0)

Change History (4)

comment:1 Changed 21 months 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 21 months 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:
01b9c3d5193fe61b82ae8b26242a13fdec22f211

Thanks to Ivan Virabyan for the report.

comment:3 Changed 21 months 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 21 months ago by ivan_virabyan

works great, thanks!

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.