-
Notifications
You must be signed in to change notification settings - Fork 265
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
NamespaceVersioning causes 404 exception in the schema generation #145
Comments
hey @maerteijn . thanks for the detailed explanation. i tried finding the issue, but it is not immediately obvious to me. in fact, the versioning tests go through that path (namespace with a viewset list could you do a reproduction? ideally in either one of those 2 spots? |
I’ll try to reproduce the issue in one of the testcases, to be continued. |
So here we go: https://github.com/tfranzel/drf-spectacular/compare/master...maerteijn:reproduce-404-with-namespace-versioning?expand=1 When you checkout my
When you change the newly added class NamespaceVersioningAPIView(generics.RetrieveUpdateDestroyAPIView):
versioning_class = NamespaceVersioning
... to class NamespaceVersioningAPIView(generics.RetrieveUpdateDestroyAPIView):
versioning_class = None
... the tests will pass |
awesome, thanks! i will investigate |
@maerteijn so that was trickier than i expected. the core problem was that namespace versioning uses the native DRF router for finding the correct route (and therefore the namespace). the resolution was super simple and did not account for path variables pattern problem should be solved for |
I can confirm this works now in the 👍 Thanks! |
awesome 👍 sry that i didn't merge any commits of yours. it occurred to me too late. |
NP, those were just 'showing what's wrong' commits, not 'this fixes the issue' commits 😄 Commit credits go to who fixed it! |
So, let's try to describe this correctly here.
When NamespaceVersioning is enabled, the schema endpoint returns a 404 when some of the url definitions contain captured values like a slug, id etc. Example:
The
modify_for_versioning
function will then be called in theSchemagenerator
:This will eventually will call a django resolver to modify the mocked request with the (versioned)
resolver_match
of the url:And here things go wrong when it can't resolve the path. This can happen because the path is already modified by
coerse_path
earlier in the process , so it won't match:And this will raise a
django.urls.exceptions.Resolver404
exception, resulting in a 404 result for the complete schema.I guess the
coerce_path
method should be called adfermodify_for_versioning
, or the 404 exception should be caught here and log a warning but I'm not yet up to speed of the complete internal functionality ofdrf-spectacular
to correctly judge this. I'm looking forward to your view on this.The text was updated successfully, but these errors were encountered: