Skip to content

Read dynamics from API v1's dynamic parameter tables, and stop mapping parameter_values.dynamic_id - #1129

Merged
anth-volk merged 7 commits into
mainfrom
v2plan/c1-52-dynamic-parameter-tables
Nov 27, 2026
Merged

anth-volk merged 7 commits into
mainfrom
v2plan/c1-52-dynamic-parameter-tables

Conversation

@anth-volk

@anth-volk anth-volk commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1128

Same-Repository Draft PR Check

  • This PR is a draft.
  • This PR is from a branch in PolicyEngine/policyengine-sim-api, not a personal fork.

Changelog

  • This PR adds a changelog fragment, 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_reform refuse a dynamic with no values; this PR keeps that refusal on the new table. It was stacked on #1122's branch and now targets main, with main merged in.

API v1 commit and the pin

Summary

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 (a nullable dynamic_id, where null means current law), apart from policy parameters and values. Its revision moves every stored row with its ID. parameter_values.dynamic_id stays in API v1 until C1 · 53 drops it.

  • Mapped classes (input_tables.py): DynamicParameter (id, name, tax_benefit_model_version_id) and DynamicParameterValue (id, dynamic_parameter_id, value_json, start_date, end_date, dynamic_id), read-only like the other input models. ParameterValue no longer maps dynamic_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.
  • Reads (policy_reform.py): _read_values and _reform_from_values take one kind of reform's mapped classes. A dynamic's values come from dynamic_parameter_values rows naming it, joined to dynamic_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, 400 dynamic_without_values) now reads the new table. Policy reads are unchanged.
  • Other readers: none. Only policy_reform.py reads parameters or parameter_values. The Modal apps, the executor, libs/policyengine-stage12-persistence, the entry project and .github/scripts read neither table, and the v2 Modal runtime takes the reform from its call.
  • Privileges (access.py): the service's role needs SELECT on both tables, so /ready and 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 it SELECT on both.
  • Test helpers (tests/public_api_rows.py):
    • insert_catalog_version stores each name in the table of its kind, by API v1's DYNAMIC_PARAMETER_PREFIXES (US gov.simulation. and simulation., UK gov.simulation. and gov.dynamic.), as API v1's publication does.
    • insert_current_law_values writes current-law values beside the values of their parameter's kind.
    • insert_dynamic writes dynamic_parameter_values.
    • insert_parameter stores 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.
  • Docs: the persistence library's README and database-access.md list the two tables.
  • No workflow, Dockerfile, Modal app, Terraform or script changes, and the change reads or declares no environment variable.

Deploy order

  • Not before C1 · 50's revision has run in production. A merge to main deploys beta, then production. This release reads tables that exist only after that revision, and /ready and the deploy smoke check fail while either is missing.
  • From that revision until this release is deployed, sim's previous release refuses every dynamic with 400 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.
  • C1 · 53 drops parameter_values.dynamic_id only 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

🤖 Generated with Claude Code

anth-volk and others added 3 commits November 26, 2026 00:34
…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>
Base automatically changed from v2plan/c1-47-empty-dynamic to main November 26, 2026 13:22
anth-volk and others added 2 commits November 26, 2026 17:34
…namic parameter tables branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk and others added 2 commits November 27, 2026 00:51
…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>
@anth-volk
anth-volk marked this pull request as ready for review November 27, 2026 15:09
@anth-volk
anth-volk requested a review from a team as a code owner November 27, 2026 15:09
@anth-volk
anth-volk merged commit fa7fb9a into main Nov 27, 2026
30 checks passed
@anth-volk
anth-volk deleted the v2plan/c1-52-dynamic-parameter-tables branch November 27, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read dynamics from API v1's dynamic_parameters and dynamic_parameter_values tables

1 participant