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

Fix /changes breaks due to multiple rows returned #341

Merged
merged 1 commit into from
Feb 1, 2024
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
5 changes: 4 additions & 1 deletion serveradmin/serverdb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ def changes(request):
# or from the change entry where the object was deleted.
server_hostname = Server.objects.filter(
server_id=OuterRef('object_id')).values('hostname')
# Workaround: In previous versions of Serveradmin restoring objects with
# the same id was possible, so we can end up with objects being deleted
# multiple times. We only take the latest into account.
change_hostname = Change.objects.filter(
object_id=OuterRef('object_id'),
change_type=Change.Type.DELETE).order_by('-id').values('change_json')
change_type=Change.Type.DELETE).values('change_json').order_by('-id')[:1]
commits = commits.prefetch_related(Prefetch(
'change_set',
queryset=Change.objects.all().annotate(hostname=Coalesce(
Expand Down
Loading