-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Check if coreapi is installed before using uritemplate or raise exception #6814
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
Conversation
This doesn’t seem right. Why do you think that coreapi needs to be installed here? (For the coreapi module generator yes, but...) |
I'm not that familiar with schema support, but maybe this is related to the coreapi/openapi renderer? |
OK, so we need a stacktrace, because there's the OLD OpenAPIRenderer (for CoreAPI to OpenAPI rendering) and then the NEW straight-to-open API flow, which really shouldn't need Without actual error details it's hard to see if there's an issue or not... |
Going to close this one off in it's current state. |
Hello! Yes, my apologies. I should have included more information. With a fresh django (2.2.3) and django rest framework installation (3.10.0) I was following the guide at: https://www.django-rest-framework.org/api-guide/schemas/
Trying to access that URL throws the following exception
Then if I install Reading the source code I found that the problem is here: # .venv/lib/python3.7/site-packages/rest_framework/compat.py
# coreapi is optional (Note that uritemplate is a dependency of coreapi) <- line 96
try:
import coreapi
import uritemplate
except ImportError:
coreapi = None
uritemplate = None So if coreapi is not installed, uritemplate is going to be None, so at this point, is required. I thought that coreapi/uritemplate were necessary for openapi thats why I added the new assert. |
Ah gotcha. What we need here is... try:
import coreapi
except ImportError:
coreapi = None
try:
import uritemplate
except ImportError:
uritemplate = None It was fine before because both coreapi and uritemplate were required. Now only uritemplate is, so we'll need to switch that compat code around a bit. |
Yes that is the fastest solution. If you want I can make a new pull request or I leave it in your hands, as you prefer. |
Good follow up @carlosgoce Thanks! |
Hello,
this just adds extra information for the developer when coreapi is not installed.
I was struggling because I was receiving the exception
I installed it and tested that
import uritemplate
was working.Reading the source code I noticed that even if you have uritemplate is not going to work without coreapi.