1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #11811 -- Data-loss bug in queryset.update.

It's now forbidden to call queryset.update(field=instance) when instance
hasn't been saved to the database ie. instance.pk is None.
This commit is contained in:
Aymeric Augustin
2013-09-06 17:13:51 -05:00
parent 73f38eb4d1
commit b4cd8169de
3 changed files with 15 additions and 1 deletions

View File

@@ -768,6 +768,8 @@ class Model(six.with_metaclass(ModelBase)):
return getattr(self, cachename)
def prepare_database_save(self, unused):
if self.pk is None:
raise ValueError("Unsaved model instance %r cannot be used in an ORM query." % self)
return self.pk
def clean(self):