Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

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

django_emptyqueryset.patch (347 bytes ) - added by jensadne 14 years ago.
patch with overriden update() returning 0
django_emptyqueryset_withtest.diff (797 bytes ) - added by cwebber 14 years ago.
Updated "patch with overriden update() returning 0", with a test

Download all attachments as: .zip

Change History (8)

by jensadne, 14 years ago

Attachment: django_emptyqueryset.patch added

patch with overriden update() returning 0

comment:1 by Alex Gaynor, 14 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:2 by Alex Gaynor, 14 years ago

Looks good, just needs tests.

by cwebber, 14 years ago

Updated "patch with overriden update() returning 0", with a test

comment:3 by cwebber, 14 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 Alex Gaynor, 14 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:5 by Adrian Holovaty, 14 years ago

Resolution: fixed
Status: newclosed

(In [12171]) Fixed #12142 -- EmptyQuerySet.update() no longer updates all rows in the database

comment:6 by Karen Tracey, 14 years ago

(In [12960]) [1.1.X] Fixed #12142 -- EmptyQuerySet.update() no longer updates all rows in the database

r12171 from trunk.

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