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
My use case is that I have an endpoint /v1/widget/100 that returns the Widget model which has has_object_read_permission. This works as expected. I've added a new custom route to the view set for /v1/widget/100/vendor that serializes a different model - Vendor, which doesn't have permission models.
It then goes to do an even weirder thing - it asserts on the obj for has_object_read/write_permissions and then shows an error with the class_name instead of the obj. This is super misleading - the obj is a Vendor and the class_name is the Widget so the error doesn't make sense.
I'm guessing this is not the wanted behaviour, but I'm not sure how to patch it and what is the right behaviour, but I'd love your feedback on what to do here.
To summarize:
There is a weird (buggy?) behaviour where the serializer is taken from the ViewSet instead of from the object checking permissions on.
The error message then doubles down on it by misleading you to think the problem is with the ViewSet model and not the object model.
WDYT? What to do?
The text was updated successfully, but these errors were encountered:
My use case is that I have an endpoint
/v1/widget/100
that returns the Widget model which hashas_object_read_permission
. This works as expected. I've added a new custom route to the view set for/v1/widget/100/vendor
that serializes a different model - Vendor, which doesn't have permission models.When calling this method without the DRF Browsable API (https://www.django-rest-framework.org/topics/browsable-api/), it works. But when I do call it with the Browasble API, I get an assertion error. Following the chain of calls DRF wants to render an HTML form for the options call, so execution eventually hits
get_rendered_html_form
(https://github.com/encode/django-rest-framework/blob/master/rest_framework/renderers.py#L456) and it indeed recognizes I'm returning a Vendor model and finds the right serializer. Eventually it callsshow_form_for_method
->check_object_permissions
(https://github.com/encode/django-rest-framework/blob/master/rest_framework/views.py#L339) ->has_object_permission
(https://github.com/dbkaplan/dry-rest-permissions/blob/master/dry_rest_permissions/generics.py#L130).When it arrives there, dry-rest-permissions wrongly parses the serializer from the ViewSet (which in my case will be the WidgetViewSet and the WidgetSerializer instead of VendorSerializer, as DRF successfully parsed). Responsible code:
https://github.com/dbkaplan/dry-rest-permissions/blob/master/dry_rest_permissions/generics.py#L137
It then goes to do an even weirder thing - it asserts on the
obj
forhas_object_read/write_permissions
and then shows an error with theclass_name
instead of the obj. This is super misleading - the obj is a Vendor and the class_name is the Widget so the error doesn't make sense.I'm guessing this is not the wanted behaviour, but I'm not sure how to patch it and what is the right behaviour, but I'd love your feedback on what to do here.
To summarize:
There is a weird (buggy?) behaviour where the serializer is taken from the ViewSet instead of from the object checking permissions on.
The error message then doubles down on it by misleading you to think the problem is with the ViewSet model and not the object model.
WDYT? What to do?
The text was updated successfully, but these errors were encountered: