Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +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.
9 changes: 9 additions & 0 deletions policyengine_api/services/economy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ def _handle_create_impact(
}
sim_params["_telemetry"] = telemetry

# The simulation gateway (policyengine-api-v2 PR #458) requires
# ``time_period`` as a string, but the upstream ``policyengine``
# package (``TimePeriodType = int``) coerces the value to int during
# ``model_validate`` and ``model_dump`` re-emits it as int. Cast back
# to str at the request boundary so the gateway's strict schema
# validates instead of returning 422.
if sim_params.get("time_period") is not None:
sim_params["time_period"] = str(sim_params["time_period"])

sim_api_execution = simulation_api.run(sim_params)
execution_id = simulation_api.get_execution_id(sim_api_execution)
run_id = getattr(sim_api_execution, "run_id", None) or telemetry["run_id"]
Expand Down
Loading