Opened 7 years ago

Closed 7 years ago

Last modified 6 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: UI/UX:

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 7 years ago.
patch with overriden update() returning 0
django_emptyqueryset_withtest.diff (797 bytes) - added by cwebber 7 years ago.
Updated "patch with overriden update() returning 0", with a test

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by jensadne

Attachment: django_emptyqueryset.patch added

patch with overriden update() returning 0

comment:1 Changed 7 years ago by Alex Gaynor

Needs documentation: unset
Needs tests: set
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by Alex Gaynor

Looks good, just needs tests.

Changed 7 years ago by cwebber

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

comment:3 Changed 7 years ago by cwebber

Added a patch, verified that it passes with the other bit of the patch applied and fails otherwise, so seems good.

comment:4 Changed 7 years ago by Alex Gaynor

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:5 Changed 7 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

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

comment:6 Changed 6 years ago by Karen Tracey

(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