Skip to content

Commit

Permalink
Fix /changes breaks due to multiple rows returned (innogames#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 and YannikSc committed Apr 19, 2024
1 parent 10de92e commit eb70d01
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 eb70d01

Please sign in to comment.