#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 , 13 years ago
| Owner: | changed from to |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:3 by , 13 years ago
I am 99% sure I found the reason for this regression. Could you verify that the bug is fixed for you?
Note:
See TracTickets
for help on using tickets.
In a62d53c03252bdf82b21b64874efe053160cbdb7: