Skip to content

Commit

Permalink
[Improvement] Handle query for the audit logs of deleted objects #558
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-olivert-riera authored Dec 12, 2024
2 parents f4e6012 + 7dcf0e7 commit 6a2356f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion promgen/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,18 @@ def get_queryset(self):

for key in self.FILTERS:
if key in self.request.GET:
obj = self.FILTERS[key].objects.get(pk=self.request.GET[key])
try:
obj = self.FILTERS[key].objects.get(pk=self.request.GET[key])
except self.FILTERS[key].DoesNotExist:
# If we can't find the object (maybe because it was deleted),
# we will search in the audit log by content_type and object_id
# and skip finding the related objects.
queryset = queryset.filter(
object_id=self.request.GET[key],
content_type_id=ContentType.objects.get_for_model(self.FILTERS.get(key)).id,
)
continue

# Get any log entries for the object itself
qset = Q(
object_id=obj.id,
Expand Down

0 comments on commit 6a2356f

Please sign in to comment.