summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-04-20 17:34:29 +0000
committerAnssi Kääriäinen <akaariai@gmail.com>2012-04-20 17:34:29 +0000
commit53fb45c6d82da6136bd06c0318c364fd076e67be (patch)
tree83c41a4a5a934fb4242a2f44b58d36defce207c6 /django
parent3d5d0be49920bfdfe501570f38c4c9ea6d05a5f5 (diff)
Fixed #17615 -- Corrected unique field validation when using multitable inheritance. The validation used wrong pk value if the parent and child model had different pk fields. Thanks ungenio for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17920 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/base.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index fc38224345..e28add30a9 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -718,9 +718,13 @@ class Model(object):
# Exclude the current object from the query if we are editing an
# instance (as opposed to creating a new one)
- if not self._state.adding and self.pk is not None:
- qs = qs.exclude(pk=self.pk)
-
+ # Note that we need to use the pk as defined by model_class, not
+ # self.pk. These can be different fields because model inheritance
+ # allows single model to have effectively multiple primary keys.
+ # Refs #17615.
+ model_class_pk = self._get_pk_val(model_class._meta)
+ if not self._state.adding and model_class_pk is not None:
+ qs = qs.exclude(pk=model_class_pk)
if qs.exists():
if len(unique_check) == 1:
key = unique_check[0]