Skip to content

Commit

Permalink
Hardcode Oscar and Django contrib models
Browse files Browse the repository at this point in the history
  • Loading branch information
rik committed Jun 18, 2020
1 parent 3afe91e commit f0095aa
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pylint_django/transforms/foreignkey.py
@@ -1,11 +1,8 @@
from itertools import chain

from astroid import (
MANAGER, nodes, InferenceError, inference_tip,
UseInferenceDefault
)
from astroid.nodes import ClassDef, Attribute

from astroid import (MANAGER, InferenceError, UseInferenceDefault, exceptions,
inference_tip, nodes)
from astroid.nodes import Attribute, ClassDef
from pylint_django.utils import node_is_subclass


Expand Down Expand Up @@ -92,8 +89,19 @@ def infer_key_classes(node, context=None):
# comparison below
module_name += '.models'
# ensure that module is loaded in astroid_cache, for cases when models is a package
if module_name not in MANAGER.astroid_cache:
MANAGER.ast_from_module_name(module_name)
for prefix in ['', 'oscar.apps.', 'django.contrib.']:
try:
if prefix + module_name not in MANAGER.astroid_cache:
MANAGER.ast_from_module_name(prefix + module_name)
except exceptions.AstroidImportError:
continue
else:
# We've imported without a crash!
module_name = prefix + module_name
break
else:
# We've exhausted the prefixes
raise ImportError(f'Could not import {module_name}')

# create list from dict_values, because it may be modified in a loop
for module in list(MANAGER.astroid_cache.values()):
Expand Down

0 comments on commit f0095aa

Please sign in to comment.