Warehouses.load_dict: skip warehouse refs to airports absent from terrain#441
Merged
rp- merged 1 commit intoJun 17, 2026
Merged
Conversation
…rain load_dict() called airport_by_id(x).load_from_dict() with no None-guard, but airport_by_id() is Optional[Airport] and returns None when a warehouse references an airport id not present in the current terrain -- aborting the whole mission load with an AttributeError. This happens with missions authored before a terrain/map update that renumbered or removed airports (e.g. Syria after the additive map update left some old ids unused). Skip the absent id instead of crashing. See pydcs#223 for a prior report of this failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Warehouses.load_dict() calls airport_by_id(x).load_from_dict(...) with no
None-guard:
But airport_by_id() is typed Optional[Airport] and returns None when a
warehouse references an airport id that isn't present in the current terrain.
That makes the call None.load_from_dict(...) → AttributeError, which aborts
the entire mission load.
This is reachable from real missions: when a mission is authored before a
terrain/map update that renumbers or removes airports, its saved warehouse data
keeps the old airport ids. The additive Syria map update is a concrete
trigger — it renumbered airports, leaving some previously-used ids (e.g. 78)
unused, so any pre-update Syria mission referencing them now fails to load.
Prior art
This is the same defect reported in #223 ("mission.load() on syria fails,
likely due to undefined warehouse-airport pairs", 2022) — a NoneType in
load_dict. That issue was self-closed by the reporter without a code fix, so
the unguarded call survived. The Syria renumber re-exposes it.
Fix
One-spot guard: if airport_by_id() returns None, skip that id and continue
to the next entry instead of crashing.
Minimal and behavior-preserving for the present-airport path: a valid airport id
loads exactly as before. Only the previously-crashing absent-id case changes —
from AttributeError to a skip. The warehouses sub-dict loop is untouched.
Test
Adds WarehousesTest.test_load_dict_skips_airport_absent_from_terrain: calls
load_dict with an airports dict containing an id not in the Caucasus
terrain followed by a valid id, and asserts (a) it does not raise and (b) the
valid airport entry still loads. The absent id is iterated first so the loop
must continue past it. (Confirmed to fail with the pre-fix AttributeError
without the guard.)