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
class RepoViewSet(ReadOnlyModelViewSet):
queryset = SoftwareRepository.objects.all()
serializer_class = RepositorySerializer
@list_route(methods=['GET', 'PUT'])
def sync(self, request):
# do stuff
However, in the api browser, if I visit that URL and then click OPTIONS then it throws a 500 error due to AssertionError being thrown by SimpleMetadata object... it seems that it tries get_object() which bombs out because it assumes that there is a pk just from it accepting PUT ?
OK, I initially though this was a bug but after a closer look at it I don't think so.
PUT are supposed to be done on a resource:
The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI.
I do consider the list_route decorator doesn't point to an existing resource nor that the URI is capable of being defined as a new resource since it's a list.
My advice would be to override the default meta.
We have a viewset something like this:
However, in the api browser, if I visit that URL and then click OPTIONS then it throws a 500 error due to AssertionError being thrown by SimpleMetadata object... it seems that it tries get_object() which bombs out because it assumes that there is a pk just from it accepting PUT ?
The text was updated successfully, but these errors were encountered: