Skip to content

Closes #21356: Implement ETag support for REST API#21522

Draft
jeremystretch wants to merge 1 commit intofeaturefrom
21356-etags
Draft

Closes #21356: Implement ETag support for REST API#21522
jeremystretch wants to merge 1 commit intofeaturefrom
21356-etags

Conversation

@jeremystretch
Copy link
Member

Closes: #21356

netbox/netbox/api/viewsets/__init__.py

  1. ETagMixin class (new, lines 37–56): Static helper _get_etag() returns a quoted ISO 8601 ETag derived from last_updated (falling back to created). The retrieve() override appends the ETag header to detail responses.
  2. NetBoxReadOnlyModelViewSet and NetBoxModelViewSet: ETagMixin added as the first base class, giving its retrieve() priority in the MRO over DRF's RetrieveModelMixin.retrieve().
  3. update(): Added an If-Match precondition check per RFC 9110 §13.1.1 — if the header is present and not *, it compares against the current ETag and returns 412 Precondition Failed on mismatch. The response now includes a
    fresh ETag reflecting the updated last_updated value.
  4. create(): Single-object creation responses now include an ETag header. Bulk creation responses do not (no single canonical object).

netbox/utilities/testing/api.py

  1. test_get_object(): After the 200 OK assertion, verifies that ChangeLoggingMixin models return an ETag header.
  2. test_update_object_with_etag() (new method): End-to-end test that verifies correct-ETag PATCH returns 200 with a changed ETag, and stale-ETag PATCH returns 412.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant