#10205 closed (fixed)
Update on a QuerySet with filter of field__in='' causes AttributeError
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | rico.bl@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Let testfield be models.CharField >>> TestModel.objects.filter(testfield__in='') [] >>> TestModel.objects.filter(testfield__in=()) [] >>> TestModel.objects.filter(testfield__in=()).delete() >>> TestModel.objects.filter(testfield__in='non-existent-entry').update(testfield='test') 0 >>> TestModel.objects.filter(testfield__in='').update(testfield='test') as well as >>> TestModel.objects.filter(testfield__in=()).update(testfield='test')
causes following trackback:
'NoneType' object has no attribute 'rowcount' File "C:\Python25\lib\site-packages\django\db\models\query.py" in update 448. rows = query.execute_sql(None) File "C:\Python25\lib\site-packages\django\db\models\sql\subqueries.py" in execute_sql 120. rows = cursor.rowcount
Attachments (1)
Change History (9)
comment:1 by , 16 years ago
Description: | modified (diff) |
---|
by , 16 years ago
Attachment: | subqueries.py.diff added |
---|
Patch to execute_sql in django/db/models/sql/subqueries.py
comment:2 by , 16 years ago
Cc: | added |
---|---|
Has patch: | set |
I've created a patch over r9904 to fix this issue.
If someone needs a quick fix without patching django, here's an ugly workaround:
try: TestModel.objects.filter(testfield__in=()).update(testfield='test') except AttributeError, e: if not e.message.find('rowcount') > 0: raise
comment:3 by , 16 years ago
Which database backend has this problem? It might be caused by a bug in the DB API wrapper, since the rowcount
attribute is meant to exist always (per PEP 249). At a minimum, I'd like to comment what bug we're working around (if it's something current), but also we should consider reporting upstream.
comment:4 by , 16 years ago
I've got this error with MySQL (mysql Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using readline 5.2)
The database gets the update but the exception is raised.
comment:6 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:7 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
cleaned up formatting.