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

Handle query for the audit logs of deleted objects #558

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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