PolicyEngine / PolicyEngine/policyengine-sim-api
Deprecate region:"us"/"uk" as the national request spelling
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1
- Forks
- 1
- Avg merge
- 10h 29m
- Merged PRs (30d)
- 7
Description
Context
National macro requests are spelled two ways today:
- Omit
region— the sim API's own convention (contract tests, integration tests, docs examples). region: "us"— what API v1 sends on every national US macro run (SimulationOptions.regionis a required string inpolicyengine-api/policyengine_api/services/economy_service.py:79; the value is stored in aNOT NULLDB column on job records). v1 is the only production caller using this spelling.
The worker accepts both via the normalisation shim at simulation_runtime.py:212-218 (None/empty/"us"/"uk" → country), and as of #637 the segmented-national eligibility does too (is_plain_national_macro). Two spellings for the same semantics means every national-detection site must remember both — #637's review caught exactly this class of drift (eligibility initially treated region:"us" as regional, which would have excluded all v1 production traffic from segmentation).
Goal
One national spelling: omit region. region:"us"/"uk" becomes deprecated, then rejected.
Migration checklist
Phase 1 — v1 stops sending it (policyengine-api):
-
economy_service.py: makeSimulationOptions.regionoptional; send noregionfor national runs (:79,_setup_sim_options:972-1006,_setup_region:1137-1149) -
_classify_simulation_geography(:1254) currently detects national viaregion == country_id— needs the omitted-region case -
reform_impacttable:region VARCHAR(32) NOT NULL— decide sentinel (e.g.national) or schema change - Routes that 400 on missing
regionquery param (economy_routes.py:52,:105-107)
Phase 2 — contract + budget window (policyengine-sim-api):
-
BudgetWindowBatchRequest.regionis a requiredstr(gateway_models.py:178) — national budget windows currently must sendregion:"us"; make it optional with omitted == national (golden + client regen) - Document in
gateway_models.pythat national == omitregion(or useregion_group)
Phase 3 — deprecation signal, then removal (policyengine-sim-api):
- Emit a deprecation warning + telemetry attribute in the
_normalise_region_codeshim (simulation_runtime.py:212-218) whenregionin{"us","uk"} - Once telemetry shows zero
region:"us"traffic: remove the shim, remove theregion in ("", country)acceptance insegmented_national.is_plain_national_macro, and reject the spelling with a clear error
Interim state
Until Phase 1 lands, the sim API MUST keep treating region:"us" as national everywhere — it is the production national traffic. #637 aligned segmentation eligibility with the worker shim so both spellings behave identically.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the migration checklist across policyengine-api and policyengine-sim-api, beginning with economy_service.py, economy_routes.py, gateway_models.py, and simulation_runtime.py. Review the existing national handling and contract or golden tests before resolving the schema and omitted-region decisions. Done means national requests omit region, deprecated us/uk requests warn and emit telemetry, and the spelling is rejected only after callers migrate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100