diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-20 16:23:25 +0300 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2013-08-21 22:31:50 +0100 |
| commit | f5552571dc7a0d9da9df1d108bc4bbef6857c157 (patch) | |
| tree | 7d4eabe2968284e8f7f4f332ede2c26db8b3708d /django | |
| parent | ced3e6b17d18174216cdbe1ec7c24cc1819db787 (diff) | |
Fixed #20820 -- Model inheritance + m2m fixture loading regression
Tests by Tim Graham, report from jeroen.pulles@redslider.net.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/fields/related.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 00da186279..6c11df4cbd 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -989,7 +989,16 @@ class ForeignObject(RelatedField): @staticmethod def get_instance_value_for_fields(instance, fields): - return tuple([getattr(instance, field.attname) for field in fields]) + ret = [] + for field in fields: + # Gotcha: in some cases (like fixture loading) a model can have + # different values in parent_ptr_id and parent's id. So, use + # instance.pk (that is, parent_ptr_id) when asked for instance.id. + if field.primary_key: + ret.append(instance.pk) + else: + ret.append(getattr(instance, field.attname)) + return tuple(ret) def get_attname_column(self): attname, column = super(ForeignObject, self).get_attname_column() |
