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

"Idempotency" of PATCH for the REST API #12196

Closed
amhn opened this issue Apr 6, 2023 · 4 comments
Closed

"Idempotency" of PATCH for the REST API #12196

amhn opened this issue Apr 6, 2023 · 4 comments
Labels
type: feature Introduction of new functionality to the application

Comments

@amhn
Copy link
Contributor

amhn commented Apr 6, 2023

NetBox version

v3.5-beta

Feature type

Change to existing functionality

Proposed functionality

The different API endpoints for a model should accept/return the same Model[1].

For example it should be possible to use the output of GET /api/ipam/ip-addresses/1/ and either POST it to /api/ipam/ip-addresses/ or PATCH it to /api/ipam/ip-addresses/1/ and (if the new object does not violate uniqueness constraints) get an updated or new object.

[1] This does not mean read_only fields should become writable, read_only fields are already ignored most of the time on PATCH/POST requests.

Use case

This would make it easier for a new user to discover the API because he can just GET an existing object, modify some fields and POST/PATCH it to get the desired changes.

For script development this would also help, because the returned object can be the same as sent one.

Database changes

No response

External dependencies

No response

@amhn amhn added the type: feature Introduction of new functionality to the application label Apr 6, 2023
@amhn
Copy link
Contributor Author

amhn commented Apr 6, 2023

Currently I did identify 3 Problems:

  • role field in Ipaddress is null on GET, but does not accept null on PATCH/POST. Filed as separate bug because this worked in 3.4. Ipaddress model does not accept null value for role, but serializer does (regression in 3.5-beta) #12195
  • ChoiceFields are dicts in GET request, but strings in POST/PATCH. Handling them can be added to netbox.api.fields.ChoiceField without breaking existing behaviour
  • Nested Object are already accepted, but read_only fields are not ignored. This can be added to netbox.api.serailizers.WritableNestedSerializer similar to ModelSerializer in django-rest-framework. That change should also be backwards compatible to existing behaviour.

I can work on the last two issues and provide a PR. This does not necessarily need to happen in the beta phase, because these changes should not affect the current documented behaviour.

Another thing is reflecting these changes in the API spec. But since the current documented behaviour is not affected, this could be added later.

@abhi1693
Copy link
Member

abhi1693 commented Apr 7, 2023

Regarding the choice field, as a developer it makes the most sense to me the way it's working currently. Changing it to as mentioned will only cause confusion and it's unnecessary as the label in the dict cannot change in a post or patch. If a user tried to send a different label for an existing value, they would expect that to change but that's not possible.

@jeremystretch
Copy link
Member

I'm fine with the proposed changes if they can be implemented in a manner that does not break backward compatibility. @amhn I'll assign this to you since you kindly offered to submit a PR; happy to provide any guidance.

@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label May 4, 2023
@jeremystretch jeremystretch added status: backlog Awaiting selection for work and removed status: accepted This issue has been accepted for implementation status: backlog Awaiting selection for work labels May 22, 2024
@jeremystretch
Copy link
Member

Closing this out as the assigned volunteer has not completed any work and there's been no further discussion.

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

3 participants