Skip to content

Commit 5d20619

Browse files
authored
Merge pull request #3522 from PolicyEngine/fix/cast-time-period-string-for-gateway
Cast time_period to string before posting to simulation gateway
2 parents 3878f3f + 52ba58c commit 5d20619

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cast time_period to string before posting to the simulation gateway. The gateway's request schema (policyengine-api-v2 PR #458) requires Optional[str], but the local policyengine package's SimulationOptions.TimePeriodType is int and model_dump re-emits int, which the gateway 422s.

policyengine_api/services/economy_service.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,15 @@ def _handle_create_impact(
511511
}
512512
sim_params["_telemetry"] = telemetry
513513

514+
# The simulation gateway (policyengine-api-v2 PR #458) requires
515+
# ``time_period`` as a string, but the upstream ``policyengine``
516+
# package (``TimePeriodType = int``) coerces the value to int during
517+
# ``model_validate`` and ``model_dump`` re-emits it as int. Cast back
518+
# to str at the request boundary so the gateway's strict schema
519+
# validates instead of returning 422.
520+
if sim_params.get("time_period") is not None:
521+
sim_params["time_period"] = str(sim_params["time_period"])
522+
514523
sim_api_execution = simulation_api.run(sim_params)
515524
execution_id = simulation_api.get_execution_id(sim_api_execution)
516525
run_id = getattr(sim_api_execution, "run_id", None) or telemetry["run_id"]

0 commit comments

Comments
 (0)