diff --git a/changelog.d/1543.fixed.md b/changelog.d/1543.fixed.md new file mode 100644 index 00000000..ab3b1625 --- /dev/null +++ b/changelog.d/1543.fixed.md @@ -0,0 +1 @@ +Fixed Modal gateway imports so routing metadata does not pull worker-only dependencies into the lightweight gateway image. diff --git a/policyengine_household_api/decorators/analytics.py b/policyengine_household_api/decorators/analytics.py index 7d19c017..49e9783c 100644 --- a/policyengine_household_api/decorators/analytics.py +++ b/policyengine_household_api/decorators/analytics.py @@ -25,7 +25,7 @@ ModalResolvedChannel, VariableUsageSummary, ) -from policyengine_household_api.utils.modal_routing_metadata import ( +from policyengine_household_api.modal_release.routing_metadata import ( REQUESTED_VERSION_ENVIRON_KEY, RESOLVED_CHANNEL_ENVIRON_KEY, ) diff --git a/policyengine_household_api/modal_release/gateway.py b/policyengine_household_api/modal_release/gateway.py index 6361ef00..2a911e77 100644 --- a/policyengine_household_api/modal_release/gateway.py +++ b/policyengine_household_api/modal_release/gateway.py @@ -13,7 +13,7 @@ empty_manifest, validate_manifest, ) -from policyengine_household_api.utils.modal_routing_metadata import ( +from policyengine_household_api.modal_release.routing_metadata import ( MODAL_ROUTING_PAYLOAD_KEY, modal_routing_payload, ) diff --git a/policyengine_household_api/utils/modal_routing_metadata.py b/policyengine_household_api/modal_release/routing_metadata.py similarity index 75% rename from policyengine_household_api/utils/modal_routing_metadata.py rename to policyengine_household_api/modal_release/routing_metadata.py index ac9123c7..a11aa2d9 100644 --- a/policyengine_household_api/utils/modal_routing_metadata.py +++ b/policyengine_household_api/modal_release/routing_metadata.py @@ -2,12 +2,14 @@ from typing import Any -from policyengine_household_api.models.analytics import ModalResolvedChannel - MODAL_ROUTING_PAYLOAD_KEY = "modal_routing" REQUESTED_VERSION_ENVIRON_KEY = "policyengine.requested_version" RESOLVED_CHANNEL_ENVIRON_KEY = "policyengine.resolved_channel" +# Keep this literal in sync with the app's channel values manually. Importing +# the shared enum here pulls heavy, unnecessary dependencies into the Modal +# gateway image and has broken production gateway startup. +RESOLVED_CHANNEL_VALUES = {"current", "frontier"} def modal_routing_payload( @@ -30,9 +32,7 @@ def routing_environ_overrides(payload: dict[str, Any]) -> dict[str, str]: resolved_channel = routing.get("resolved_channel") if not isinstance(requested_version, str) or not requested_version: return {} - if resolved_channel not in { - channel.value for channel in ModalResolvedChannel - }: + if resolved_channel not in RESOLVED_CHANNEL_VALUES: return {} return { diff --git a/policyengine_household_api/modal_release/worker_dispatch.py b/policyengine_household_api/modal_release/worker_dispatch.py index e6c3e4d3..f5042f87 100644 --- a/policyengine_household_api/modal_release/worker_dispatch.py +++ b/policyengine_household_api/modal_release/worker_dispatch.py @@ -2,7 +2,7 @@ from typing import Any -from policyengine_household_api.utils.modal_routing_metadata import ( +from policyengine_household_api.modal_release.routing_metadata import ( routing_environ_overrides, ) diff --git a/tests/unit/endpoints/test_household.py b/tests/unit/endpoints/test_household.py index b8b5e602..089187cc 100644 --- a/tests/unit/endpoints/test_household.py +++ b/tests/unit/endpoints/test_household.py @@ -3,7 +3,7 @@ import pytest from policyengine_household_api.constants import COUNTRY_PACKAGE_VERSIONS from policyengine_household_api.endpoints.household import _validate_axes -from policyengine_household_api.utils.modal_routing_metadata import ( +from policyengine_household_api.modal_release.routing_metadata import ( REQUESTED_VERSION_ENVIRON_KEY, RESOLVED_CHANNEL_ENVIRON_KEY, ) diff --git a/tests/unit/modal_release/test_gateway.py b/tests/unit/modal_release/test_gateway.py index 9298afef..5ee34767 100644 --- a/tests/unit/modal_release/test_gateway.py +++ b/tests/unit/modal_release/test_gateway.py @@ -11,7 +11,7 @@ from policyengine_household_api.modal_release.manifest import ( MANIFEST_SCHEMA_VERSION, ) -from policyengine_household_api.utils.modal_routing_metadata import ( +from policyengine_household_api.modal_release.routing_metadata import ( MODAL_ROUTING_PAYLOAD_KEY, ) diff --git a/tests/unit/modal_release/test_worker_dispatch.py b/tests/unit/modal_release/test_worker_dispatch.py index 8898b05d..87b9fcaa 100644 --- a/tests/unit/modal_release/test_worker_dispatch.py +++ b/tests/unit/modal_release/test_worker_dispatch.py @@ -3,7 +3,7 @@ from policyengine_household_api.modal_release.worker_dispatch import ( dispatch_to_flask_app, ) -from policyengine_household_api.utils.modal_routing_metadata import ( +from policyengine_household_api.modal_release.routing_metadata import ( MODAL_ROUTING_PAYLOAD_KEY, REQUESTED_VERSION_ENVIRON_KEY, RESOLVED_CHANNEL_ENVIRON_KEY,