From 5c72e0754a438af1ea1cb1643528da7ce1df4b42 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 31 Mar 2023 16:00:07 -0700 Subject: [PATCH] Fix iteration error when splitting transfers. If one type of unit is zeroed but there are still other units to check in the dict, the dict will have changed size during iteration. Iterate on a copy of the dict instead. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2773. --- game/transfers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/game/transfers.py b/game/transfers.py index d7a68b2d..ca913272 100644 --- a/game/transfers.py +++ b/game/transfers.py @@ -616,7 +616,10 @@ class PendingTransfers: raise ValueError units = {} - for unit_type, remaining in transfer.units.items(): + # If one type of unit is zeroed but there are still other units to check in the + # dict, the dict will have changed size during iteration. Iterate on a copy of + # the dict instead. + for unit_type, remaining in dict(transfer.units).items(): take = min(remaining, size) size -= take transfer.take_units(unit_type, take)