PolicyEngine / PolicyEngine/policyengine-sim-api

Deprecate region:"us"/"uk" as the national request spelling

Open
#638 0 comments 0 reactions 0 assignees View on GitHub

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.region is a required string in policyengine-api/policyengine_api/services/economy_service.py:79; the value is stored in a NOT NULL DB 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: make SimulationOptions.region optional; send no region for national runs (:79, _setup_sim_options :972-1006, _setup_region :1137-1149)
  • _classify_simulation_geography (:1254) currently detects national via region == country_id — needs the omitted-region case
  • reform_impact table: region VARCHAR(32) NOT NULL — decide sentinel (e.g. national) or schema change
  • Routes that 400 on missing region query param (economy_routes.py:52, :105-107)

Phase 2 — contract + budget window (policyengine-sim-api):

  • BudgetWindowBatchRequest.region is a required str (gateway_models.py:178) — national budget windows currently must send region:"us"; make it optional with omitted == national (golden + client regen)
  • Document in gateway_models.py that national == omit region (or use region_group)

Phase 3 — deprecation signal, then removal (policyengine-sim-api):

  • Emit a deprecation warning + telemetry attribute in the _normalise_region_code shim (simulation_runtime.py:212-218) when region in {"us","uk"}
  • Once telemetry shows zero region:"us" traffic: remove the shim, remove the region in ("", country) acceptance in segmented_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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.