Optimize object-based permissions enforcement #7144

Closed
opened 2025-12-29 20:19:42 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Oct 21, 2022).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

When evaluating whether a newly-created object satisfies any permission constraints, call exists() on the queryset rather than first().

Justification

first() returns the complete row and loads the instance into memory, whereas exists() merely indicates whether the object with the specified PK is found, which is all we need to evaluate permissions.

Originally created by @jeremystretch on GitHub (Oct 21, 2022). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes When evaluating whether a newly-created object satisfies any permission constraints, call `exists()` on the queryset rather than `first()`. ### Justification `first()` returns the complete row and loads the instance into memory, whereas `exists()` merely indicates whether the object with the specified PK is found, which is all we need to evaluate permissions.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 20:19:42 +01:00
adam closed this issue 2025-12-29 20:19:43 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7144