summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-09-06 17:13:51 -0500
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-09-06 17:15:23 -0500
commitb4cd8169de604943f8aaee3666282c95e650e5f4 (patch)
tree58c3b9f4fc8ef77fafa0e24f396d0d98eb75864e /django
parent73f38eb4d15d3da4707d8637178334c2f105ca19 (diff)
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.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/base.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 2ca6f3ecc2..a9d8695f21 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -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):