Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy fails due to SimpleJWT trying to access SECRET_KEY #731

Open
PureTryOut opened this issue Jul 27, 2023 · 4 comments
Open

mypy fails due to SimpleJWT trying to access SECRET_KEY #731

PureTryOut opened this issue Jul 27, 2023 · 4 comments

Comments

@PureTryOut
Copy link

Currently our CI is failing due to mypy failing to find SECRET_KEY as used by SimpleJWT.

$ mypy . --check-untyped-defs
Traceback (most recent call last):
Error constructing plugin instance of NewSemanalDjangoPlugin
  File "/home/runner/work/beep-backend/beep-backend/.venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 95, in main
  File "mypy/main.py", line 174, in run_build
  File "mypy/build.py", line 197, in build
  File "mypy/build.py", line 242, in _build
  File "mypy/build.py", line 503, in load_plugins
  File "mypy/build.py", line 484, in load_plugins_from_config
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/mypy_django_plugin/main.py", line 77, in __init__
    self.django_context = DjangoContext(self.plugin_config.django_settings_module)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/mypy_django_plugin/django/context.py", line 84, in __init__
    apps, settings = initialize_django(self.django_settings_module)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/mypy_django_plugin/django/context.py", line 68, in initialize_django
    apps.populate(settings.INSTALLED_APPS)
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/django/apps/config.py", line 269, in import_models
    self.models_module = import_module(models_module_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/rest_framework_simplejwt/models.py", line 6, in <module>
    from .settings import api_settings
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/rest_framework_simplejwt/settings.py", line 19, in <module>
    "SIGNING_KEY": settings.SECRET_KEY,
                   ^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/beep-backend/beep-backend/.venv/lib/python3.11/site-packages/django/conf/__init__.py", line 111, in __getattr__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")

django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

Strangely, this doesn't happen if I run mypy locally, only in CI where setup is basically the same.
I tried running DJANGO_SETTINGS_MODULE=<path to settings> mypy . but it did not work. How can I get this package compatible with mypy?

@bonface221
Copy link

do you have the secret key in the settings file? @PureTryOut

@PureTryOut
Copy link
Author

Yes, where else would it be?

@bonface221
Copy link

how do I know is it my project!!

@PureTryOut
Copy link
Author

Well in a bare django-admin startproject project the secret key is already set in the settings file. I don't see why I or anyone else would ever move it, so that's why I'm asking where else it would be. Genuine interest, not trying to be snarky or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants