#12142 closed (fixed)
Calling update() on EmptyQuerySet updates all rows in database
Reported by: | jensadne | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.1 |
Severity: | Keywords: | EmptyQuerySet | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Assuming a model Foo, with a CharField "bar" of which there is for instance 42 stored instances in the database.
Foo.objects.none().count() returns the expected result 0.
However, Foo.objects.none().update(bar='baz') returns 42, and all 42 rows in the database have been updated.
This seems to be caused by EmptyQuerySet not overriding update(), this method should be overridden to just return 0.
Attachments (2)
Change History (8)
by , 15 years ago
Attachment: | django_emptyqueryset.patch added |
---|
comment:1 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 15 years ago
Attachment: | django_emptyqueryset_withtest.diff added |
---|
Updated "patch with overriden update() returning 0", with a test
comment:3 by , 15 years ago
Added a patch, verified that it passes with the other bit of the patch applied and fails otherwise, so seems good.
comment:4 by , 15 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:5 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
patch with overriden update() returning 0