Skip to content

Commit d2ee9f6

Browse files
committed
Better error message when Django is not configured. Closes #277
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!
1 parent 017241e commit d2ee9f6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pylint_django/transforms/foreignkey.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def _module_name_from_django_model_resolution(model_name, module_name):
5353

5454

5555
def infer_key_classes(node, context=None):
56+
from django.core.exceptions import ImproperlyConfigured # pylint: disable=import-outside-toplevel
57+
5658
keyword_args = []
5759
if node.keywords:
5860
keyword_args = [kw.value for kw in node.keywords if kw.arg == 'to']
@@ -106,6 +108,9 @@ def infer_key_classes(node, context=None):
106108
# 'auth.models', 'User' which works nicely with the `endswith()`
107109
# comparison below
108110
module_name += '.models'
111+
except ImproperlyConfigured:
112+
raise RuntimeError("DJANGO_SETTINGS_MODULE required for resolving ForeignKey "
113+
"string references, see Usage section in README!")
109114

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

0 commit comments

Comments
 (0)