Skip to content

PUT /api/dandisets/{id}/versions/{version}/ returns incorrect 405 for non-draft versions #2742

@waxlamp

Description

@waxlamp

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 body

Suggested 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions