Skip to content
New issue

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

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

Already on GitHub? # to your account

Spectacular ignores settings #768

Closed
georgkrause opened this issue Jul 13, 2022 · 4 comments
Closed

Spectacular ignores settings #768

georgkrause opened this issue Jul 13, 2022 · 4 comments

Comments

@georgkrause
Copy link

Describe the bug
I set some parameters in my settings.py SPECTACULAR_SETTINGS but it wont get picked up

To Reproduce
I placed the example from the docs in my settings.py:

SPECTACULAR_SETTINGS = {
    'TITLE': 'Your Project API',
    'DESCRIPTION': 'Your project description',
    'VERSION': '1.0.0',
    'SERVE_INCLUDE_SCHEMA': False,
    # OTHER SETTINGS
}

I confirmed its part of the settings using python manage.py shell and printed settings.SPECTACULAR_SETTINGS and the settings are there. But running python manage.py spectacular I get an openapi definition without title, description or version.

Expected behavior
The generated specification contains all above specified parameters.

@tfranzel
Copy link
Owner

Hi,

that sounds really suspicious. Are you 100% certain those two commands run under the exact same shell/environment? This has come up a couple of times and every time it was some misconfigured settings.py, where there was simply another settings.py used or debug flags that only conditionally set the SPECTACULAR_SETTINGS var.

This works for a lot of people so i'm quite confident it is something in your setup. If you can provide a reproduction I can certainly take a deeper look.

@georgkrause
Copy link
Author

@tfranzel thanks for the reply. I am almost not believing its not my setups fault, but I spent so many hours trying everything to see if I can get it to work - but no cigar.

I am confident its the same shell. I am sure the settings.py is loaded, when I remove INSTALLED_APPS += ("drf_spectacular",) in the same file and rerun spectacular, its failing. There is also no condition.

I have no minimal way to reproduce it at hand, because I am not sure which part of my setup actually causes the problems and I fail to see how I can get more debug information. But luckily the whole setup is public, so I can link it. Here is my settings.py: https://dev.funkwhale.audio/funkwhale/funkwhale/-/blob/develop/api/config/settings/local.py

An example run in CI is also available: https://dev.funkwhale.audio/funkwhale/funkwhale/-/jobs/109712

I know this is a lot of information and I can try to answer more questions. I'd just really appreciate your help since I am lost and my next idea would be to dig in the code, where you are likely way more familiar with. So thank you for any hint in advance :)

@tfranzel
Copy link
Owner

So I gave it a look and I believe it is a problem with the import order. You import OpenApiAuthenticationExtension which depends on plumbing, which again depends on django.settings. So the code attempts to load the settings while you are still processing your settings.py file.

related issue #307. We fixed the circular import issues back then, but apparently that does not mean it will work correctly.

Putting arbitrary imports in the settings.py is kind of bad practice anyway. Put your extensions in a separate file and do something like this suggestion: https://drf-spectacular.readthedocs.io/en/latest/faq.html#where-should-i-put-my-extensions-my-extensions-are-not-detected

Let me know if that was the issue.

@georgkrause
Copy link
Author

@tfranzel Cool, this works perfectly. Thank you for checking it and sorry for not noticing this FAQ before.

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

No branches or pull requests

2 participants