Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH request on a token changes the key value #17279

Closed
dchiquito opened this issue Aug 27, 2024 · 1 comment · Fixed by #17294
Closed

PATCH request on a token changes the key value #17279

dchiquito opened this issue Aug 27, 2024 · 1 comment · Fixed by #17294
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@dchiquito
Copy link

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.

@dchiquito dchiquito added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Aug 27, 2024
@caineblood

This comment was marked as resolved.

@netbox-community netbox-community deleted a comment from YeGop0218 Aug 27, 2024
@bctiemann bctiemann added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: needs triage This issue is awaiting triage by a maintainer labels Aug 27, 2024
@jeremystretch jeremystretch self-assigned this Aug 28, 2024
@jeremystretch jeremystretch added severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available labels Aug 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants