Skip to content

Saved reports keep the growth settings of their reform's indexed changes again, for now - #4414

Draft
anth-volk wants to merge 7 commits into
masterfrom
v2plan/d1-10-saved-reports-growth-settings
Draft

anth-volk wants to merge 7 commits into
masterfrom
v2plan/d1-10-saved-reports-growth-settings

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #4413

Summary

Saved reports keep the growth settings of their reform's indexed changes again, for now. App v3 lets a reform set a parameter from one year on and then grow it with an index (such as CPI-U) or as current law grows it, with rounding; a policy keeps only the yearly values that gives, so the saved report is the only place the settings live. #4402 stopped storing them, so app v3 could no longer reopen an indexed change as indexed. This partly reverses #4402, under the old names, as a temporary home: a later project moves the settings into policies and drops the column.

  • API v2 maps user_report_associations.provisions again (no exclude_properties). No Alembic revision and no data change: the column never left the table. The columns_left_out_of_the_mapper category of direct SQLAlchemy use goes, since no model uses it now.
  • POST /v2/user-reports and PATCH /v2/user-reports/{id} take provisions without the deprecated mark. Only indexed items are kept: growth set and not fixed (an empty string counts as not indexed). Each stored item is path plus the growth keys it sets (growth, growth_start, growth_base, growth_round_to, growth_round). Values, labels and dated schedules are checked as before (64 KiB cap, no NaN or Infinity, no unknown keys) and discarded. breadcrumb, baseline_value and value become optional, so app v3 can send only the path and settings; older builds' full items are accepted again and their settings kept. On PATCH, a list replaces the settings, null clears them, and leaving the field out keeps them.
  • The owner's read and list, GET /v2/shared-reports/{id}, GET /v2/me/export and the admin saved-items read return provisions as a list of ReportGrowthSettingsItem (keys not set are absent, not null), or null. Rows saved before Saved reports stop storing and returning a copy of the reform's changes #4402 hold full copies of the reform's changes; reads return them read down to the same settings without changing the row. A stored item whose growth keys don't hold their JSON types is skipped, and a column holding no list gives no settings, so one row never fails a list or an export.
  • Published-report reads still don't return provisions.
  • Docs: the Alembic guide's paragraph on columns a mapper leaves out and the Stage 12A doc (request bounds, shared-report item, schema list). Generated migration contract files refreshed; contract registry lists provisions again for the user-report and shared-report routes. Changelog fragment saved-reports-growth-settings.added.md.

Migration scope: the report route group (/v2/user-reports, /v2/shared-reports/{id}) and the account export and admin saved-items reads that return saved reports. Nothing changes on the Flask/API v1 path, and nothing new is prepared for other services. User-visible API contract changes, intended: provisions is returned again on those reads, and the request field is no longer deprecated, with breadcrumb, baseline_value and value optional. No inline ruff suppressions added.

It fixes a test that fails on master: tests/unit/v2/test_me_routes.py::test_export_answers_the_current_run_of_each_saved_report passes provisions=None to UserReportRead (from #4386), which #4402 removed, so it fails with a TypeError there.

Testing

Failing tests first (b1c9f689b), then the change (ae2c64e8a). New tests/unit/v2/test_saved_report_growth_settings.py replaces test_saved_report_reform_copy.py, and the column-only test class saved_report_reform_copies.py goes (its users store through the model). Changed: the report and shared-report route tests (round trip, settings-only save, keys echoed only when stored, OpenAPI types), the account-service, export and admin tests, the model and persistence-category tests, the published-page test and its fixture, the contract registry, and tests/integration/test_v2_user_identity_persistence.py::test_non_finite_numbers_never_reach_jsonb.

Each test run by its own node ID (21 nodes, 42 cases with parameters, including the integration test against a disposable PostgreSQL 17 database):

  • on b1c9f689b: 26 failed, 16 passed (unchanged parameter cases and the published-page assertion). The failures were assertions, or TypeError/AttributeError where tests pass or read provisions on read records that had no such field yet, or a validation error where a save sends only path and settings;
  • on ae2c64e8a: 42 passed.

Review fixes, each test first: 6c595b10b then b519104d7 (4 cases: 4 failed, then 4 passed), and 5e0b18699 then 2299e0a08 (1 test: failed, then passed).

Checks: make quality-check (ruff, ruff format, lint-imports, mypy on its configured files, the quality guards including the migration-contract and rules guards) passed; alembic -c alembic-v2.ini check against the disposable database found no new operations; python -m scripts.rules validate passed.

Review

Three rounds of adversarial review before this PR:

  • Round 1 (policyengine-api-v2plan-d1-10-saved-reports-growth-settings-review-round1-2026-12-04.md): no high or medium bugs; one low: the read copied growth values without type checks and assumed a list, so a malformed row (only possible by a manual edit) would make the response item raise. Fixed in b519104d7. It also found a test docstring this branch had made wrong; restored.
  • Round 2 (...-review-round2-2026-12-05.md): no high or medium bugs; one low: a stored integer growth_round_to too large for a float passed the read and the response item refused it. Fixed in 2299e0a08, and the response item's description now says the settings are temporary.
  • Round 3 (...-review-round3-2026-12-05.md): no bugs. Its note that the request item's OpenAPI description named an internal function is fixed in f6c37fe9e.

Bugs left: none. Points left as they are: the growth keys are declared in the request model, the read function and the response item (the old shape, kept for a temporary column); the request model still converts input as it did before #4402 (for example growth_start: true becomes 1); OpenAPI shows the optional growth keys as nullable, as before #4402; reading old rows is tested on SQLite only.

Merge order

This is task D1 · 10 of the detailed-save API project. Every earlier task is complete: D1 · 0 to D1 · 7a are deployed, and D1 · 8 (#4400) and D1 · 9 are merged; none of their deployments is needed, since this change uses only a column that has always existed and #4402's code. The merge waits only for this PR's checks. It builds on master, not on another task's branch. No deployment code changes, so there is no environment table.

The app side (saving the settings again and reopening indexed changes as indexed in Build) is a separate app v3 task, which needs this deployed.

🤖 Generated with Claude Code

anth-volk and others added 7 commits December 4, 2026 23:36
Saved reports keep, in `provisions`, the growth settings of each indexed
change in their reform (path plus the growth keys, without values), as app v3
sent them before D1 · 5. Saves and updates store them, every user-report
read and /v2/shared-reports/{id} return them, and rows saved before D1 · 5
are read down to their settings. The column-only test class goes, since the
model maps the column again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
App v3 lets a reform's change grow from one year on with an index or with
current law, and a policy keeps only the yearly values that gives, so the
saved report is the only place the settings live. D1 · 5a stopped storing
them, which left app v3 unable to reopen an indexed change as indexed.

API v2 maps `user_report_associations.provisions` again. Saves and updates
keep the `path` and growth keys of each indexed change (growth set and not
`fixed`) and discard other changes, values, labels and dated schedules; a
change's `breadcrumb`, `baseline_value` and `value` become optional. The
owner's reads, `/v2/shared-reports/{id}`, the account export and the admin
saved-items read return the settings, and rows saved before D1 · 5 are read
down to them. Published reports still return none. No revision is needed:
the column never left the table. Project 17 moves the settings into policies
and drops the column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 found that a stored growth key of the wrong type, or a column
holding something other than a list, reaches the response item, which raises,
so one such row fails the owner's list, the account export and the admin
saved-items read. The tests read such rows through the response item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A read keeps a stored item only when each growth key it sets holds its JSON
type (no booleans for numbers), and a column that holds no list gives no
settings, so one row can never fail a list or an export. Restore the
simulation-role privilege test's wording, which was right: since revision
4e30076d4b9f no model of the simulation tables leaves a column out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 found that a stored integer `growth_round_to` too large for a
float passes the read, and the response item refuses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A number stored for `growth_round_to` must convert to a finite float, as the
response item requires, or the read skips the item. The saved report's
response item also says the settings are temporary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.27273% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.94%. Comparing base (57202c0) to head (f6c37fe).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
policyengine_api/services/v2/user_reports/types.py 71.42% 6 Missing and 6 partials ⚠️
.../fastapi_routes/v2/user_reports/response_models.py 60.00% 0 Missing and 4 partials ⚠️
...ne_api/services/v2/user_reports/transformations.py 0.00% 1 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (67.27%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4414      +/-   ##
==========================================
- Coverage   93.99%   93.94%   -0.06%     
==========================================
  Files         459      459              
  Lines       26259    26308      +49     
  Branches     4088     4104      +16     
==========================================
+ Hits        24682    24714      +32     
- Misses        901      908       +7     
- Partials      676      686      +10     
Flag Coverage Δ
integration 60.90% <67.27%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch was successfully deployed

1 active deployment
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.

Saved reports keep the growth settings of their reform's indexed changes again, for now

1 participant