From f38c5327ea44f728be47144560a357bf1030cd79 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 6 Mar 2026 22:46:40 +0000 Subject: [PATCH] Fix YAML validation outside Flask app context --- agenda/trip.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/agenda/trip.py b/agenda/trip.py index 17673ee..9779831 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -351,17 +351,18 @@ def build_trip_list( def add_coordinates_for_unbooked_flights( - routes: list[StrDict], coordinates: list[StrDict] + routes: list[StrDict], coordinates: list[StrDict], data_dir: str ) -> None: """Add coordinates for flights that haven't been booked yet.""" - if not ( - any(route["type"] == "unbooked_flight" for route in routes) - and not any(pin["type"] == "airport" for pin in coordinates) - ): + if not any(route["type"] == "unbooked_flight" for route in routes): return - data_dir = flask.current_app.config["PERSONAL_DATA"] airports = typing.cast(dict[str, StrDict], travel.parse_yaml("airports", data_dir)) + existing_airport_names = { + typing.cast(str, pin["name"]) + for pin in coordinates + if pin.get("type") == "airport" and isinstance(pin.get("name"), str) + } iata_codes: set[str] = set() for route in routes: if route["type"] != "unbooked_flight": @@ -375,14 +376,18 @@ def add_coordinates_for_unbooked_flights( airport = airports.get(iata) if not airport: continue + airport_name = typing.cast(str, airport["name"]) + if airport_name in existing_airport_names: + continue coordinates.append( { - "name": airport["name"], + "name": airport_name, "type": "airport", "latitude": airport["latitude"], "longitude": airport["longitude"], } ) + existing_airport_names.add(airport_name) def stations_from_travel(t: StrDict) -> list[StrDict]: @@ -640,6 +645,8 @@ def get_coordinates_and_routes( routes.append(route) seen_routes.add(route["key"]) + add_coordinates_for_unbooked_flights(routes, coordinates, data_dir) + for route in routes: if "geojson_filename" in route: route["geojson"] = read_geojson(data_dir, route.pop("geojson_filename"))