Repository navigation
Refuse a dynamic with no parameter values instead of running it as current law - #1122
Merged
Merged
Conversation
…rrent law (failing)
Tests for C1 · 47. API v1 refuses to store a dynamic without values, so a
dynamic for which sim reads no parameter_values rows has values this
release can't see, such as values moved to tables it doesn't read. Running
it as current law would store that result under a key naming the dynamic.
- read_dynamic_reform raises DynamicWithoutValuesError for a dynamic with no
rows, alone or with a policy; a dynamic whose values all start after 2200
is still read, as {} (it passes already, and pins that only a dynamic
with no rows is refused).
- The economy and household stores raise it, a report side's wrapped in
ReportSideError, and the side refusal type includes it.
- Every route answers it 400 dynamic_without_values: economy simulations,
reports and budget windows, household calculations and reports, and the
re-runs of reports, simulations and household reports. The OpenAPI
document lists the code for the economy and household routes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rrent law C1 · 47. API v1 refuses to store a dynamic without values, so when sim finds a dynamic but no parameter_values row for it, the values are stored where this release doesn't read them (as after C1 · 50's revision moves them to their own tables). Running such a dynamic as current law stored that result under a key naming the dynamic, which later requests reused. - read_dynamic_reform raises DynamicWithoutValuesError when no value row names the dynamic, after the existence and country check. The rows are read once (_read_values) and turned into the reform separately (_reform_from_values). A dynamic whose values are read but whose periods hold no day, such as values starting after 2200, is still read as no change. - SideRefusal includes it, so every report side's refusal names its side. - Every route answers it 400 dynamic_without_values, a code among the service's state codes, as unknown_catalog_version is while a release deploys: economy simulations, reports and budget windows, household reports and every re-run through simulation_values_refusal, with a detail written from the request; household calculations with the store's text, as that route's other refusals. API v1 answers a sim 400 with any code other than unknown_region, unknown_dataset and unknown_dynamic as 503, with the code and reason, so it needs no change. - Every path reads a dynamic's values through read_dynamic_reform before it finds or creates any row, and nothing reads them after submission, so this one check covers them all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…branch # Conflicts: # projects/policyengine-simulation-entry/tests/test_economy_reruns.py
…sion Review round 1: the session-signature test still named _read_reform, which the change split into _read_values and _reform_from_values, so its case raised AttributeError and the two new functions went unchecked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s re-run Review round 1's code-quality findings: - The household calculation route's 400 description and module docstring, the HouseholdRefusalCode comment, and the refusal errors' and read_refusal's docstrings now name a dynamic with no parameter values this release reads, not only a missing row or function. - A budget window's re-run refuses a side's dynamic without values, naming the side and creating no window run or call; a simulation's re-run starts no Modal call for one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s can't be read (failing) Review round 2's code-quality findings, tests first: - The economy create routes', re-run routes' and household calculation route's OpenAPI 400 descriptions name dynamic_without_values. - The reader's message says the dynamic has no parameter values the service can read, as every route's detail does; the household calculation route passes it on as its detail. - A report asking for cliffs, and a re-run asking for them, with a side's dynamic without values, writes and starts no cliff calculation (passes already); the report submission test raises the store's ReportSideError and checks the report's detail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s can't be read Review round 2's code-quality findings: - The economy create routes' and re-run routes' 400 descriptions give dynamic_without_values as one of the service's states, and the household calculation route's names the code. - DynamicWithoutValuesError's message says the dynamic has no parameter values the service can read, so the household calculation route's detail, which passes it on, says what every other route's says. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
November 26, 2026 13:22
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1121
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Changelog
changelog.d/<name>.<type>.md, whose type is breaking, added, changed, fixed or removed:changelog.d/c1-47-empty-dynamic.changed.md.After #1113
This PR was stacked on
v2plan/c1-44-household-dynamics(#1113), which changed the same function (read_dynamic_reformgained a country check, andread_simulation_reformis shared by economy and household paths). #1113 has merged, and this PR now targetsmain.public-api-commitismain's,825a9b3c.Summary
API v1 refuses to create a dynamic with no values, so when sim finds a dynamic but no
parameter_valuesrow for it, the values are stored where this release doesn't read them. That is every dynamic once API v1 moves dynamics' values to their own tables, until sim reads those tables. Until now sim ran such a dynamic as current law and stored the result under a definition key that includesdynamic_id, so later identical requests reused it.read_dynamic_reformraises the newDynamicWithoutValuesErrorwhen noparameter_valuesrow names the dynamic, after the existence and country check. The rows are read once (_read_values) and turned into the reform separately (_reform_from_values), both on ORM mapped classes.read_dynamic_reform(viaread_simulation_reform) before it finds or creates any row or starts a Modal call: economy simulations, reports and budget windows; household calculations; household reports; and the re-runs of reports, budget windows, simulations and household reports, which read the stored record's dynamic again. A report or re-run asking for cliffs reads them before it writes or starts any cliff calculation. Nothing reads a dynamic's values after submission: the v2 Modal runtime takes the reform from its call, and a budget window's later years from the first year's input.SideRefusalincludes the new error, so a report side's refusal names its side.dynamic_without_values, listed among the service-state codes (likeunknown_catalog_versionwhile a release deploys), notunknown_dynamic, since the dynamic exists. The detail is written from the request, for example "us's stored dynamic that the request's reform names has no parameter values the service can read."; the household calculation route passes the store's text, as it does for its other refusals. API v1 needs no change: it answers a sim 400 with any code other thanunknown_region,unknown_datasetandunknown_dynamicas 503, with the code and reason, for reports, simulations, budget windows, household reports and re-runs, and every household calculation 400 as 503.dynamic_without_values.run_simulationcode (src/modal/app.pyand its modules) imports anything added here.Deploy order
parameter_valueswould run every dynamic as current law and store that result.Testing
d8825b30failing tests,98836e21the change; review fixesa11dbbb0,f97cef8c,4840b4f6(failing tests) andd775da71;43a91ba5andb340f328merge Household calculations and reports apply a dynamic, and every simulation refuses another country's dynamic #1113's branch at36f61d43andaee0634c, and8225b035mergesmainafter Household calculations and reports apply a dynamic, and every simulation refuses another country's dynamic #1113 merged.825a9b3c(revision4e30076d4b9f) with its grants: 61 persistence cases and 29 entry cases pass.🤖 Generated with Claude Code