You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When I try to use extend_schema for an action which has a mapping method, swagger ui will break and returns this error:
AssertionError: Incompatible AutoSchema used on View <class 'client.admin.user.user_api.UserApi'>. Is DRF's DEFAULT_SCHEMA_CLASS pointing to "drf_spectacular.openapi.AutoSchema" or any other drf-spectacular compatible AutoSchema?
To Reproduce
For a configured ModelViewSet api, use @extend_schema_view and add a mapping method for an action which has extend_schema.
Expected behavior
It would be really nice if the error describes what to do...
I have the same issue. I reverse engineered back to get_view_method_names() not handling methods registered through mapping.*, and this cascades to the assert that raises the message to compare the ExtendedSchema type itself to AutoSchema, instead of an instance of it.
I made a makeshift fix that causes the get_view_method_names() method to register the method:
Hi, so looks like a corner case in internal initialization. Unfortunately, you hit the one combination that is not properly dealt with. The others are already covered by tests.
@action decorated
@*.mapping.* decorated
Result
case 1
No
No
✅
case 2
Yes
No
❌
case 3
No
Yes
✅
case 4
Yes
Yes
✅
HOTFIX: For now, just add a empty decorator to circumvent this edge case. It should be fixed, but I deem this low priority at the moment.
@extend_schema_view(list=extend_schema(responses=ZSerializer), )classXViewset(mixins.ListModelMixin, viewsets.GenericViewSet):
...
@extend_schema(responses=XSerializer)@action(methods=["put"], detail=False, url_path="personalization")defpersonalization(self, request, *args, **kwargs):
pass@extend_schema() # <---- this is the important part; may or may not contain parameters.@personalization.mapping.getdefget_personalization(self, request, *args, **kwargs):
pass
Describe the bug
When I try to use
extend_schema
for an action which has a mapping method, swagger ui will break and returns this error:AssertionError: Incompatible AutoSchema used on View <class 'client.admin.user.user_api.UserApi'>. Is DRF's DEFAULT_SCHEMA_CLASS pointing to "drf_spectacular.openapi.AutoSchema" or any other drf-spectacular compatible AutoSchema?
To Reproduce
For a configured ModelViewSet api, use
@extend_schema_view
and add a mapping method for an action which hasextend_schema
.Expected behavior
It would be really nice if the error describes what to do...
Here is sample code:
user_api.py
And here is my serializser:
Here is my settings.py:
How error disappears?
You need to comment out
extend_schema
forpersonalization
in@extend_schema_view
OR
Comment the mapped method, I mean below function:
and the swagger ui loads with no error...
BTW, thanks alot @tfranzel for the package! 🙏
The text was updated successfully, but these errors were encountered: