Skip to content

Refuse a dynamic with no parameter values instead of running it as current law - #1122

Merged
anth-volk merged 9 commits into
mainfrom
v2plan/c1-47-empty-dynamic
Nov 26, 2026
Merged

anth-volk merged 9 commits into
mainfrom
v2plan/c1-47-empty-dynamic

Conversation

@anth-volk

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

Copy link
Copy Markdown
Contributor

Fixes #1121

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-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_reform gained a country check, and read_simulation_reform is shared by economy and household paths). #1113 has merged, and this PR now targets main. public-api-commit is main's, 825a9b3c.

Summary

API v1 refuses to create a dynamic with no 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. 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 includes dynamic_id, so later identical requests reused it.

  • The check. read_dynamic_reform raises the new DynamicWithoutValuesError when no parameter_values 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), both on ORM mapped classes.
  • What counts as no values. Only a dynamic with no stored rows. A dynamic whose values are read but whose periods hold no day a calculation can be for (values with no end date that start after 2200) is still read, as no change: current law is that dynamic's correct result.
  • Where it runs. Every path reads a dynamic's values through read_dynamic_reform (via read_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. SideRefusal includes the new error, so a report side's refusal names its side.
  • What a request gets. 400 with the new code dynamic_without_values, listed among the service-state codes (like unknown_catalog_version while a release deploys), not unknown_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 than unknown_region, unknown_dataset and unknown_dynamic as 503, with the code and reason, for reports, simulations, budget windows, household reports and re-runs, and every household calculation 400 as 503.
  • Docs. Both READMEs, the OpenAPI 400 descriptions of the economy, re-run and household calculation routes, and the code enums name dynamic_without_values.
  • Nothing in the v1 run_simulation code (src/modal/app.py and its modules) imports anything added here.

Deploy order

  • In production before API v1's revision that moves dynamics' values to their own tables runs there (and in staging before it runs there, which sim's release gives both). Without this, a sim release that still reads parameter_values would run every dynamic as current law and store that result.
  • After Household calculations and reports apply a dynamic, and every simulation refuses another country's dynamic #1113, which has merged. Nothing else constrains it: it reads no new column, needs no grant, and adds a code API v1 already handles.
  • The later sim change that reads dynamics' values from the new tables keeps this refusal.

Testing

🤖 Generated with Claude Code

anth-volk and others added 8 commits November 25, 2026 17:49
…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
anth-volk marked this pull request as ready for review November 26, 2026 13:22
@anth-volk
anth-volk merged commit 20dcc6e into main Nov 26, 2026
28 of 30 checks passed
@anth-volk
anth-volk deleted the v2plan/c1-47-empty-dynamic branch 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>
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.

Refuse a dynamic with no parameter values instead of running it as current law

1 participant