Calling update() on EmptyQuerySet updates all rows in database

View: New views
2 Messages — Rating Filter:   Alert me  

Calling update() on EmptyQuerySet updates all rows in database

by Jens Ådne Rydland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-developers@...
To unsubscribe from this group, send email to django-developers+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Calling update() on EmptyQuerySet updates all rows in database

by Jacob Kaplan-Moss-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Tue, Nov 3, 2009 at 7:42 AM, Jens Ådne Rydland <jensadne@...> 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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-developers@...
To unsubscribe from this group, send email to django-developers+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---