You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When making queries, soft deleted items are included in the queryset unless explicitly filtered out e.g deleted_at__isnull=True. It is easy to forget to exclude soft deleted records. The side effect is accidental exposure of deleted records when returning API responses.
We should use a custom manager that excludes soft deleted items by default, but also provides an API for getting all records including soft deleted items.
Benefits of implementing the feature/enhancement
Prevents accidental exposure of soft deleted items.
Suggested implementation plan(Steps to be taken to implement feature)
Create a custom queryset with methods to exclude soft-deleted records and to include all records.
class SoftDeleteQuerySet(models.QuerySet):
def active(self):
return self.filter(deleted_at__isnull=True)
def all_with_deleted(self):
return self
Create a custom manager that makes use of the custom queryset
Suggested Feature / Enhancement
When making queries, soft deleted items are included in the queryset unless explicitly filtered out e.g
deleted_at__isnull=True
. It is easy to forget to exclude soft deleted records. The side effect is accidental exposure of deleted records when returning API responses.We should use a custom manager that excludes soft deleted items by default, but also provides an API for getting all records including soft deleted items.
Benefits of implementing the feature/enhancement
Prevents accidental exposure of soft deleted items.
Suggested implementation plan(Steps to be taken to implement feature)
The text was updated successfully, but these errors were encountered: