Calling update() on EmptyQuerySet updates all rows in database

1 view
Skip to first unread message

Jens Ådne Rydland

unread,
Nov 3, 2009, 7:42:19 AM11/3/09
to django-d...@googlegroups.com
Came across an issue with EmptyQuerySet today, it seems it does not
behave correctly with regard to update(). (or that the documentation is
lacking, I suspect it's the former)

Assuming I have a model Foo of which I have say 42 stored instances in
the database, each with a CharacterField "bar".

If I do Foo.objects.none().count() I get 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(),
shouldn't this just return 0?

--
best regards, Jens Ådne Rydland

Jacob Kaplan-Moss

unread,
Nov 3, 2009, 9:05:41 AM11/3/09
to django-d...@googlegroups.com
On Tue, Nov 3, 2009 at 7:42 AM, Jens Ådne Rydland <jens...@pvv.ntnu.no> wrote:
> This seems to be caused by EmptyQuerySet not overriding update(),
> shouldn't this just return 0?

Yup, that's a bug. Can you please open a ticket so that we don't forget this?

Jacob

Reply all
Reply to author
Forward
0 new messages