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
Thomas DA COSTA committed Feb 6, 2023
1 parent f9a8f9d commit d2ccca2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pylint_django/transforms/foreignkey.py
Expand Up @@ -116,8 +116,19 @@ def infer_key_classes(node, context=None):
) from exep

# 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 d2ccca2

Please sign in to comment.