Skip to content

PATCH request on a token changes the key value #17279

@dchiquito

Description

@dchiquito

Deployment Type

Self-hosted

NetBox Version

v4.0.9

Python Version

3.10

Steps to Reproduce

Make an API call like this:

requests.patch(
    "http://localhost:32768/api/users/tokens/42/",
    json={"write_enabled": False, "description": "modified"}, # Note that key is omitted
    headers={"Authorization": "Token 0123456789abcdef0123456789abcdef01234567"},
)

Expected Behavior

Only fields explicitly listed in the PATCH request should be updated.

Observed Behavior

Any PATCH to a token that omits the key field will repopulate the key field with a randomly generated default value.

This is happening because users.api.serializers.tokens.TokenSerializer.to_internal_value is explicitly setting key if it is not set in the request body. I'm not sure why this is necessary, as the Token model is doing essentially the same thing by overriding save.

Metadata

Metadata

Assignees

Labels

severity: mediumResults in substantial degraded or broken functionality for specfic workflowsstatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions