Skip to content

Commit

Permalink
Fix /changes breaks due to multiple rows returned (#341)
Browse files Browse the repository at this point in the history
In the previous days of Serveradmin we allowed to restore objects with
the same id. This can lead to an object being in the history as deleted
multiple times.
  • Loading branch information
kofrezo authored Feb 1, 2024
1 parent 0faca47 commit 7f5a3f8
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit 7f5a3f8

Please sign in to comment.