From bcdd9e180758bb027c39bfddc9995a474fc296fd Mon Sep 17 00:00:00 2001 From: zhexu14 <64713351+zhexu14@users.noreply.github.com> Date: Mon, 30 Jun 2025 19:53:10 +1000 Subject: [PATCH] Handle scenaio where flight that is not added to the ATO (flight in the process of being created) is deleted (#3512) --- qt_ui/models.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qt_ui/models.py b/qt_ui/models.py index f968605b..f6741cd7 100644 --- a/qt_ui/models.py +++ b/qt_ui/models.py @@ -174,10 +174,15 @@ class PackageModel(QAbstractListModel): EventStream.put_nowait(GameUpdateEvents().update_flight(flight)) # If there are no more flights in the package, delete the package. if len(self.package.flights) == 0: - flight.squadron.coalition.ato.remove_package(flight.package) - # Update ATO model so packages list is refreshed. - is_player = flight.squadron.coalition.player - self.game_model.ato_model_for(is_player).replace_from_game(is_player) + # Check if package is in ATO first as flight may still be "tentative" i.e. + # not added to the ATO yet. + if flight.package in flight.squadron.coalition.ato.packages: + flight.squadron.coalition.ato.remove_package(flight.package) + # Update ATO model so packages list is refreshed. + is_player = flight.squadron.coalition.player + self.game_model.ato_model_for(is_player).replace_from_game( + is_player + ) def delete_flight(self, flight: Flight) -> None: """Removes the given flight from the package."""