diff options
| author | Simon Charette <charette.s@gmail.com> | 2020-04-05 01:25:59 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-07 09:20:46 +0200 |
| commit | 1d16c5d562a67625f7309cc7765b8c57d49bf182 (patch) | |
| tree | 1789601daa010165cfe4c6298ec028f6dc95f12d /django | |
| parent | e03eb8db9371c2af864b124701b8f970ff405ca9 (diff) | |
Refs #27666 -- Ensured relationship consistency on delayed reloads.
Delayed reloads of state models broke identity based relationships
between direct and non-direct ancestors.
Basing models.Options related objects map of model labels instead of
their identity ensured relationship consistency is maintained.
Refs #30966.
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/options.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index f027a74976..0e28b6812a 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -698,7 +698,8 @@ class Options: ) for f in fields_with_relations: if not isinstance(f.remote_field.model, str): - related_objects_graph[f.remote_field.model._meta.concrete_model._meta].append(f) + remote_label = f.remote_field.model._meta.concrete_model._meta.label + related_objects_graph[remote_label].append(f) for model in all_models: # Set the relation_tree using the internal __dict__. In this way @@ -706,7 +707,7 @@ class Options: # __dict__ takes precedence over a data descriptor (such as # @cached_property). This means that the _meta._relation_tree is # only called if related_objects is not in __dict__. - related_objects = related_objects_graph[model._meta.concrete_model._meta] + related_objects = related_objects_graph[model._meta.concrete_model._meta.label] model._meta.__dict__['_relation_tree'] = related_objects # It seems it is possible that self is not in all_models, so guard # against that with default for get(). |
