Repository navigation
Read dynamics from API v1's dynamic parameter tables, and stop mapping parameter_values.dynamic_id - #1129
Merged
Conversation
…ables (failing) API v1's C1 · 50 moves dynamic parameters into `dynamic_parameters`, and their current-law values and every dynamic's values into `dynamic_parameter_values`. The test helpers now store each parameter in the table of its kind, as API v1 does: `insert_catalog_version` by API v1's prefixes, with optional current-law values, `insert_dynamic` in `dynamic_parameter_values`, and `insert_parameter` for the overlap tests' name in both tables, a state API v1 never stores. New tests: a dynamic's parameters' current-law values are never read as its own; each reform's names are found among its own kind of parameter alone; the input models map both tables, and `ParameterValue` maps no `dynamic_id`. The service's privilege list and the rule's grant fixtures name both tables. They fail until sim maps and reads the new tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
API v1's C1 · 50 keeps dynamic parameters in `dynamic_parameters`, and their current-law values and every dynamic's values in `dynamic_parameter_values`, apart from policy parameters and values. - `input_tables.py` maps both tables (`DynamicParameter`, `DynamicParameterValue`), and `ParameterValue` no longer maps `dynamic_id`, which C1 · 53 drops from API v1's table. - `policy_reform.py`: `_read_values` and `_reform_from_values` take one kind of reform's mapped classes. A dynamic's values and names come from the new tables, and the running catalog version's dynamic parameters decide what it lacks. C1 · 47's refusal of a dynamic without values reads `dynamic_parameter_values`. Policy reads are unchanged. - `access.py`: the service's role needs `SELECT` on both tables, so `/ready` and the deploy smoke check report them when missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `_ReformModels` holds how one policy's or dynamic's values are selected (`owned_by`), so `_read_values` takes only the owner's ID and a value table can't be paired with the other table's owner condition. - The database-access guide lists every API v1 table a calculation is read from, `dynamics`, `regions` and `datasets` included; the library README's edited paragraphs say "API v1" and are wrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…namic parameter tables branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…anch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`public-api-commit` moves from `825a9b3c9` (C1 · 41's merge) to `806b1ec9a`, PolicyEngine/policyengine-api#4347's merge into `master`, whose revision `7f7335f0eb31` creates `dynamic_parameters` and `dynamic_parameter_values` and grants the service's role SELECT on both. The `Public API schema` job builds the tables at this commit, so the tests of the new tables run against them. 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 #1128
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-52-dynamic-parameter-tables.changed.md.After #1122
This PR builds on #1122 (merged 2026-11-26), which made
read_dynamic_reformrefuse a dynamic with no values; this PR keeps that refusal on the new table. It was stacked on #1122's branch and now targetsmain, withmainmerged in.API v1 commit and the pin
masteron 2026-11-26 as806b1ec9a(revision7f7335f0eb31, with its grants).libs/policyengine-simulation-persistence/public-api-commit) moves from825a9b3c9(C1 · 41's merge) to806b1ec9ain258dc9a8. That also brings C1 · 43 (Let users save named dynamics through /v2/user-dynamics policyengine-api#4337), C1 · 45 (Take a dynamic on household calculations and household reports policyengine-api#4343) and C1 · 48 (Make UK gov.dynamic a model assumption, and add a command that splits stored policies holding model assumptions policyengine-api#4345) into the schema thePublic API schemajob builds; the comparisons of sim's models with it pass locally.Public API schemafailed on the 30 cases that read or write the two new tables, each because the pinned schema had neither table, andCI completefailed with it.Summary
API v1's C1 · 50 keeps dynamic parameters in
dynamic_parameters, and their current-law values and every dynamic's values indynamic_parameter_values(a nullabledynamic_id, where null means current law), apart from policy parameters and values. Its revision moves every stored row with its ID.parameter_values.dynamic_idstays in API v1 until C1 · 53 drops it.input_tables.py):DynamicParameter(id,name,tax_benefit_model_version_id) andDynamicParameterValue(id,dynamic_parameter_id,value_json,start_date,end_date,dynamic_id), read-only like the other input models.ParameterValueno longer mapsdynamic_id. The comparison of read-only models checks only the columns they map (read_column_differences), so the column API v1 keeps until C1 · 53 causes no difference.policy_reform.py):_read_valuesand_reform_from_valuestake one kind of reform's mapped classes. A dynamic's values come fromdynamic_parameter_valuesrows naming it, joined todynamic_parameters, and its names are checked against the running catalog version's dynamic parameters. A dynamic parameter's current-law values are never read. Refuse a dynamic with no parameter values instead of running it as current law #1122's refusal of a dynamic with no values (DynamicWithoutValuesError, 400dynamic_without_values) now reads the new table. Policy reads are unchanged.policy_reform.pyreadsparametersorparameter_values. The Modal apps, the executor,libs/policyengine-stage12-persistence, the entry project and.github/scriptsread neither table, and the v2 Modal runtime takes the reform from its call.access.py): the service's role needsSELECTon both tables, so/readyand the deploy smoke check report either one missing. The rule proof's grant fixtures list both. The Modal worker role's list doesn't change: its calls read no input table, although API v1 grants itSELECTon both.tests/public_api_rows.py):insert_catalog_versionstores each name in the table of its kind, by API v1'sDYNAMIC_PARAMETER_PREFIXES(USgov.simulation.andsimulation., UKgov.simulation.andgov.dynamic.), as API v1's publication does.insert_current_law_valueswrites current-law values beside the values of their parameter's kind.insert_dynamicwritesdynamic_parameter_values.insert_parameterstores one name in a named table. Five tests of a policy and a dynamic setting the same parameter use it to put the name in both tables, a state API v1 never stores.database-access.mdlist the two tables.Deploy order
maindeploys beta, then production. This release reads tables that exist only after that revision, and/readyand the deploy smoke check fail while either is missing.dynamic_without_values(Refuse a dynamic with no parameter values instead of running it as current law #1122), which API v1 answers as 503, because the values it reads have moved.parameter_values.dynamic_idonly after this release is in production: earlier releases filter a dynamic's values on that column, so their dynamic reads would fail with a database error instead of the 400. Their policy reads select named columns only, so they keep working.Testing
8c8c8a85failing tests (before the change, 20 of the 153 cases the change affected failed, each because sim read the old tables or lists, andtest_mapped_classes.pycould not import the new classes),8578ee76the change,ea894418review round 1's code-quality fixes.513904c4merges Refuse a dynamic with no parameter values instead of running it as current law #1122's branch at8225b035(mainwith Household calculations and reports apply a dynamic, and every simulation refuses another country's dynamic #1113's release),2db16a87mergesmain(Refuse a dynamic with no parameter values instead of running it as current law #1122, Report in worker telemetry whether each call's container was restored from a memory snapshot #1124) anda6052d9emergesmain(Request 1 CPU and 10 GiB for the segment workers #1126, Plan, build and look up prebuilt year files and baselines through country and dataset-level handlers #1132, Remove the plain worker functions and the gateway's fallback to them, and refuse rollbacks to apps without the worker class #1131), all with no conflicts.258dc9a8moves the pin.test_public_api_schema.py, the Modal worker role's privilege check and the pin file's format check), 129 node IDs (299 cases) in all, run by node ID against a disposable database built by API v1's migrations at the new pin806b1ec9a(revision7f7335f0eb31) with its grants: all pass. The changed tests also passed at C1 · 50's earlier commitsf2b51c20d,aca49e387,cb162caadand302f17355, and against825a9b3c9alone the 30 cases above failed. The Stage 12 library's tests, which thePublic API schemajob also runs, were not run locally.sim.persistence.orm-onlyrule's tests pass. The full suites were not run locally; CI runs them.ea894418).🤖 Generated with Claude Code