-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Description
In VersionViewSet.update() (dandiapi/api/views/version.py), when a PUT request targets a non-draft version, the handler returns HTTP 405 with a plain string body:
if version.version != 'draft':
return Response(
'Only draft versions can be modified.',
status=status.HTTP_405_METHOD_NOT_ALLOWED,
)There are two problems with this:
1. Wrong status code
HTTP 405 Method Not Allowed has a specific meaning: the HTTP method (here, PUT) is not supported on the target URL. It should be accompanied by an Allow header listing valid methods. That's not the situation here — PUT is perfectly valid on this URL; it just can't be applied to a published version's current state. A more appropriate status code would be:
- 409 Conflict — the request conflicts with the current state of the resource, or
- 422 Unprocessable Entity — the request is well-formed but cannot be acted upon
2. Inconsistent response body
All other errors from this endpoint go through DRF's exception machinery and return a standard JSON envelope:
{"detail": "..."}This response returns a raw string instead, which breaks any client code that parses errors uniformly.
Contrast
The very next guard in the same method raises a proper DRF-compatible exception:
if version.dandiset.unembargo_in_progress:
raise DandisetUnembargoInProgressError # → 400, JSON bodySuggested fix
Replace the return Response(...) with a raised DRF exception (e.g. ValidationError or a custom DandiError subclass) using an appropriate status code, so the response shape is consistent with the rest of the API.