Skip to content

a viewset's action list gets "head" added to it, but only after being called at least once #9747

Open

Description

@rtpg

https://github.com/encode/django-rest-framework/blame/853969c69c815be69513c2f63a41285858a45352/rest_framework/viewsets.py#L106-L107

We didn't have head set in our actions on a viewset, but head would suddenly appear in a viewset's actions, but seemingly randomly.

This way of filling in head in actions means that before you call a viewset at least once, it will have one set of actions, but afterwards it would have another.

This is surprising to me, and I have a hard time imagining it to be the right solution here. But perhaps I am missing a detail.

Activity

  1. browniebroke commented on Jul 25, 2025

    @browniebroke
    Collaborator

    Seems like this behaviour is due to what was done in #7223 for #6196

    Do you have a suggestion on how to fix that?

  2. Sajadrahimi commented on Aug 25, 2025

    @Sajadrahimi

    I guess the initial idea of changing SimpleRouter and action decorator was the better way to go with. I applied to changes here, it seems fine to me if you're fine with it I can open a PR @browniebroke .

  3. auvipy commented on Dec 14, 2025

    @auvipy
    Collaborator

    you can open a pr for review

  4. mag123c commented on Dec 18, 2025

    @mag123c
    Contributor

    Taking this on since no PR has been opened yet.

  5. Natgho commented on Mar 2, 2026

    @Natgho
    Contributor

    This solution seems quite sufficient. It will eliminate mutation-related errors;
    #9853 mutation source

  6. browniebroke commented on Mar 2, 2026

    @browniebroke
    Collaborator

    I'm not sure... The OP flags the mutation problem but is not clear on expected behaviour. The current fix makes sure head is never present in the viewset actions, but one could argue that it should always be there

  7. Natgho commented on Mar 2, 2026

    @Natgho
    Contributor

    I'm not sure... The OP flags the mutation problem but is not clear on expected behaviour. The current fix makes sure head is never present in the viewset actions, but one could argue that it should always be there

    Should the basic flow of behavior change? In this logic, partially yes. What if someone only wants to accept "GET" requests but does not accept "HEAD" requests? I think the current solution addresses this.

  8. EliArn99 commented on Aug 20, 2026

    @EliArn99

    Hi! I'd be interested in working on this. It looks like the actions mapping is mutated inside the request closure, so view.actions changes after the first request. Would moving the implicit HEAD mapping to as_view() initialization (without mutating the caller-provided mapping) be an acceptable direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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