Code

Opened 4 years ago

Closed 4 years ago

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

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by jensadne

patch with overriden update() returning 0

comment:1 Changed 4 years ago by Alex

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by Alex

Looks good, just needs tests.

Changed 4 years ago by cwebber

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

comment:3 Changed 4 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 4 years ago by Alex

  • Needs tests unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 4 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:6 Changed 4 years ago by kmtracey

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

r12171 from trunk.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.