Skip to content

Commit

Permalink
Better error message when Django is not configured. Closes #277
Browse files Browse the repository at this point in the history
if Django isn't configured, that is DJANGO_SETTINGS_MODULE isn't
available in the environment, then raise a RuntimeError with message

DJANGO_SETTINGS_MODULE required for resolving ForeignKey string
references, see Usage section in README!
  • Loading branch information
atodorov committed Aug 4, 2020
1 parent 927dc1e commit c240a8e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pylint_django/transforms/foreignkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def _module_name_from_django_model_resolution(model_name, module_name):


def infer_key_classes(node, context=None):
from django.core.exceptions import ImproperlyConfigured # pylint: disable=import-outside-toplevel

keyword_args = []
if node.keywords:
keyword_args = [kw.value for kw in node.keywords if kw.arg == 'to']
Expand Down Expand Up @@ -106,6 +108,9 @@ def infer_key_classes(node, context=None):
# 'auth.models', 'User' which works nicely with the `endswith()`
# comparison below
module_name += '.models'
except ImproperlyConfigured:
raise RuntimeError("DJANGO_SETTINGS_MODULE required for resolving ForeignKey "
"string references, see Usage section in README!")

# ensure that module is loaded in astroid_cache, for cases when models is a package
if module_name not in MANAGER.astroid_cache:
Expand Down

0 comments on commit c240a8e

Please sign in to comment.