tfranzel / drf-spectacular

Sane and flexible OpenAPI 3 schema generation for Django REST framework.
https://drf-spectacular.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.37k stars 263 forks source link

Getting working drf-spectacular package for Debian 11 stable #411

Closed eLvErDe closed 3 years ago

eLvErDe commented 3 years ago

Hello,

I'm sorry to bother you with such issue, as I guessed, it's occurring on my side but I fails to understand what's going on here... It used to works just fine with 0.11.1 but fails with 0.13.1. I did not try with newer version because I did not find anything related in changelog. Why is failing when trying to import this module if I'm not using it ?

Thanks a lot in advance,

Best regards, Adam. traceback.txt

tfranzel commented 3 years ago

Hi

File "/usr/lib/python3/dist-packages/drf_spectacular/contrib/rest_auth.py", line 3, in File "/opt/myexe/my_app/util-usersprofiles-api/users_profiles/urls.py", line 24, in pytest.importorskip("dj_rest_auth") File "/usr/lib/python3/dist-packages/_pytest/outcomes.py", line 212, in importorskip raise Skipped(reason, allow_module_level=True) from None Skipped: could not import 'dj_rest_auth': No module named 'dj_rest_auth'

i can't really follow how that is possible with version 0.13.1. there is no import in line 3 of contrib/rest_auth.py. not sure where this is supposed to be coming from. are you sure this is the release you are using?

generally this should not happen and we do guard against it. please try the latest version, as we do not retroactively fix issues. does it still happen with 0.16.0?

tfranzel commented 3 years ago

and pytest.importorskip("dj_rest_auth") is not part of spectacular. please check that the bug is not in your code :smile:

eLvErDe commented 3 years ago

Yup, I was figuring out, it's actually some hacky stuff added by the Debian maintainer to make it work without dj_rest_auth but it seems to be failing completely. Should I assume dj_rest_auth is a hard dependency of your module ?

Regards, Adam.

tfranzel commented 3 years ago

absolutely not! all contrib packages are optional and are only loaded when the package is actually available/used. we have very little dependencies apart from DRF and Django. these are our hard deps:

https://github.com/tfranzel/drf-spectacular/blob/master/requirements/base.txt

we added some logic for maintainer last year to remedy the "distributor issue" with missing packages and running our tests. since then our tests do run with pytest --skip-missing-contrib, but that should not even come up if you are a regular user. if the distributor changed things in non-test files he probably broke the package with that.

if at all possible you should try to use the pypi release.

eLvErDe commented 3 years ago

Well, that's a very interresting comment, so it seems the debian maintainer patch broke everything while it should work out of box. Let's drop the patch and see how it goes...

eLvErDe commented 3 years ago

Indeed, it seems better but I still see some tests failing (0.16.0):

/usr/lib/python3/dist-packages/django/urls/conf.py:34: in include
    urlconf_module = import_module(urlconf_module)
/usr/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:953: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
    ???
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'dj_rest_auth', import_ = <function _gcd_import at 0x7f06e7c92e18>

>   ???
E   ModuleNotFoundError: No module named 'dj_rest_auth'

<frozen importlib._bootstrap>:965: ModuleNotFoundError
_____________________________ test_rest_auth_token _____________________________

no_warnings = <_pytest.capture.CaptureFixture object at 0x7f06e3312160>
settings = <pytest_django.fixtures.SettingsWrapper object at 0x7f06e33129b0>

    @pytest.mark.contrib('dj_rest_auth', 'allauth', 'rest_framework_simplejwt')
    @mock.patch('drf_spectacular.settings.spectacular_settings.SCHEMA_PATH_PREFIX', '')
    def test_rest_auth_token(no_warnings, settings):
        settings.REST_USE_JWT = True
        # flush module import cache to re-evaluate conditional import
>       import dj_rest_auth.urls
E       ModuleNotFoundError: No module named 'dj_rest_auth'

tests/contrib/test_rest_auth.py:34: ModuleNotFoundError

Test are run using: PYTHONHASHSEED=3114101546 {interpreter} runtests.py --fast

Any idea why they are not skipped ?

Thanks a lot !

tfranzel commented 3 years ago

i don't understand why you run tests on upstream packages when you are only using them.

apart from that you are running all the tests with that command. this is the default for spectacular developers. you would want to run this instead, where the missing packages are skipped:

PYTHONHASHSEED=3114101546 {interpreter} runtests.py --fast --skip-missing-contrib
eLvErDe commented 3 years ago

Because I'm trying to get this (https://packages.debian.org/search?keywords=python3-djangorestframework-spectacular) working, as an official debian package (which looks currently borked to me)

tfranzel commented 3 years ago

ahh i see. i did not realize in what capacity you were asking. from that perspective your questions make a lot more sense. thanks for helping out!

that parameter was added exclusively added for package maintainers. does it work now?

eLvErDe commented 3 years ago

It indeed seems a lot better, but I also had to ensure minimum version on a couple of packages... I'll do my best to get it fixed before Debian 11 release but I'm affraid I spotted this too late :(

tfranzel commented 3 years ago

thanks anyway for chipping in! i suppose we can close this issue then. feel free to ask if i can give support you there.

eLvErDe commented 3 years ago

If you want we can leave it open to track official debian package status of your module. I'm trying to sort this out but the COVID-19 vaccine just kicked so it's getting hard to get focused... Doing my best...

tfranzel commented 3 years ago

yeah sure. we can leave it open. maybe rename it to make the scope visible... like prefix with debian or something.

expect 1-2 days being flu sick. :face_with_head_bandage: wish you the best! :rocket:

eLvErDe commented 3 years ago

Well, it's all good, I updated the official debian packaging here: https://salsa.debian.org/python-team/packages/python-drf-spectacular

And confirmed this version is working perfectly fine for me.

I also opened a grave bug in the hope it's not too late to get it updated for the incoming stable release: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=989305

Thanks a lot for your help :)

tfranzel commented 3 years ago

closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up.