diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2014-05-12 13:46:47 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2014-05-17 17:36:45 -0300 |
| commit | 862e1ff2340a1e28a3e7c6904d2b0283085f34c8 (patch) | |
| tree | 4b575b6eb0fc68426efd754c1585c805c777ff62 /django | |
| parent | e520a73eeea6b185b719901ab9985ecef00e5664 (diff) | |
Fixed #22421 -- Regression in fixtures loading.
Loading fixtures were failing since the refactoring in 244e2b71f5 for
inheritance setups where the chain contains abstract models and the
root ancestor contains a M2M relation.
Thanks Stanislas Guerra for the report.
Refs #20946.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/fields/related.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index bad457f571..ceae2cd563 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -1440,14 +1440,16 @@ class ForeignObject(RelatedField): @staticmethod def get_instance_value_for_fields(instance, fields): ret = [] + opts = instance._meta 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. - opts = instance._meta if field.primary_key: possible_parent_link = opts.get_ancestor_link(field.model) - if not possible_parent_link or possible_parent_link.primary_key: + if (not possible_parent_link or + possible_parent_link.primary_key or + possible_parent_link.model._meta.abstract): ret.append(instance.pk) continue ret.append(getattr(instance, field.attname)) |
