diff options
Diffstat (limited to 'django/db/models/options.py')
| -rw-r--r-- | django/db/models/options.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index c81a61c916..9f0746bd58 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -3,7 +3,6 @@ import inspect import warnings from bisect import bisect from collections import OrderedDict, defaultdict -from contextlib import suppress from django.apps import apps from django.conf import settings @@ -269,8 +268,10 @@ class Options: # is a cached property, and all the models haven't been loaded yet, so # we need to make sure we don't cache a string reference. if field.is_relation and hasattr(field.remote_field, 'model') and field.remote_field.model: - with suppress(AttributeError): + try: field.remote_field.model._meta._expire_cache(forward=False) + except AttributeError: + pass self._expire_cache() else: self._expire_cache(reverse=False) @@ -518,8 +519,10 @@ class Options: # Due to the way Django's internals work, get_field() should also # be able to fetch a field by attname. In the case of a concrete # field with relation, includes the *_id name too - with suppress(AttributeError): + try: res[field.attname] = field + except AttributeError: + pass return res @cached_property @@ -531,8 +534,10 @@ class Options: # Due to the way Django's internals work, get_field() should also # be able to fetch a field by attname. In the case of a concrete # field with relation, includes the *_id name too - with suppress(AttributeError): + try: res[field.attname] = field + except AttributeError: + pass return res def get_field(self, field_name): @@ -749,10 +754,12 @@ class Options: # Creates a cache key composed of all arguments cache_key = (forward, reverse, include_parents, include_hidden, topmost_call) - with suppress(KeyError): + try: # In order to avoid list manipulation. Always return a shallow copy # of the results. return self._get_fields_cache[cache_key] + except KeyError: + pass fields = [] # Recursively call _get_fields() on each parent, with the same |
