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
can not use custom DEFAULT_PAGINATOR_INSPECTORS #382
Comments
It's probably a circular import issue. Try breaking things up in separate modules. |
Thanks for the reply. Given how simple and little the sample code I provided is and given that it only imports code from the external libs Perhaps you import django's Paginators in the same file where |
Looking at the stack trace, it's a cyclic import:
Which suggets that the file contains more than you've shown, i.e. an You could argue that this is a bug in |
Oops, you are right about the stack trace, I got it mixed up when pasting it here. I updated and simplified the example and stack trace in the original post to match the given example, where there is nothing else in the file than what is shown. The stack trace seems to say that the import error happens when importing the paginator inspector: |
Well then, that's strange. Using acc204e I can't reproduce the error. |
Ok I found out the issue. Thank you very much for your help and reactivity. It seems that cf. in the given settings example, When I move SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {"basic": {"type": "basic"}},
"DEFAULT_INFO": "api.info.api_info",
"DEFAULT_PAGINATOR_INSPECTORS": [
'api.inspector.PageNumberPaginatorInspectorClass',
]
} |
I'm having this problem and can't for the life of me break the circular dependency. I have a file in from drf_yasg.inspectors.base import FilterInspector, NotHandled, openapi
class URLParamFilterInspector(FilterInspector):
def get_filter_parameters(self, filter):
if not filter.__name__ == "URLParamFilter":
return NotHandled
return [
openapi.Parameter(
filter.field_name, openapi.IN_QUERY, type=openapi.TYPE_STRING
)
] And in SWAGGER_SETTINGS = {
"DEFAULT_INFO": {
"title": "API",
},
"SECURITY_DEFINITIONS": {
"JWT": {"type": "apiKey", "name": "Authorization", "in": "header"},
},
"DEFAULT_MODEL_RENDERING": ["example", "model"],
"DEFAULT_FILTER_INSPECTORS": ["content.inspectors.URLParamFilterInspector"],
} I fire up
I also get this error when attempting to start the development server normally, using I'm not sure how I'm meant to subclass |
If I try and cheese it like so: from drf_yasg import openapi
class URLParamFilterInspector:
def get_filter_parameters(self, filter):
if not filter.__name__ == "URLParamFilter":
return None
return openapi.Parameter(
filter.field_name, openapi.IN_QUERY, type=openapi.TYPE_STRING
) I get the error:
|
Added more cheese but it didn't work: def URLParamFilterInspector():
from drf_yasg import openapi
from drf_yasg.inspectors import FilterInspector, NotHandled
class _URLParamFilterInspector(FilterInspector):
def get_filter_parameters(self, filter):
if not filter.__name__ == "URLParamFilter":
return NotHandled
return openapi.Parameter(
filter.field_name, openapi.IN_QUERY, type=openapi.TYPE_STRING
)
return _URLParamFilterInspector Error:
You've made it difficult to trick your project into doing what I want to do 😄 |
If anybody sees the same error, check if you imported the custom inspector in any other views. It caused circular import for me and removing all and just setting the DEFAULT_FILTER_INSPECTORS in Django settings, the errors have gone. |
Issue workaround resolution here. |
Hi,
I can not set a custom paginator inspector as default using this
DEFAULT_PAGINATOR_INSPECTORS
option that is in the docs:https://drf-yasg.readthedocs.io/en/stable/settings.html#default-paginator-inspectors.
Here are the step to reproduce. I have a simple
api
module in which I created a fileswagger.py
with the following :Here is my django config in
settings.py
for swagger:When generating the swagger file with the CLI, it throws the following error:
Am I doing something wrong or is there a bug here?
How come
api.swagger.api_info
is correctly imported butapi.swagger.PageNumberPaginatorInspectorClass
is not?The text was updated successfully, but these errors were encountered: