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 9becc56
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pylint_django/transforms/foreignkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)
from astroid.nodes import ClassDef, Attribute

from django.core.exceptions import ImproperlyConfigured
from pylint_django.utils import node_is_subclass


Expand Down Expand Up @@ -106,6 +107,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 9becc56

Please sign in to comment.