From 862e1ff2340a1e28a3e7c6904d2b0283085f34c8 Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Mon, 12 May 2014 13:46:47 -0300 Subject: 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. --- django/db/models/fields/related.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'django') 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)) -- cgit v1.3