Repository navigation
Require every API v2 report's type in reports.type, and read it in API v1 - #4400
Merged
Merged
Conversation
The v2 revision test module was at 1,465 of the 1,500 lines allowed for test code. The shared reports, published reports, published report images and saved reports' current runs revision tests move, unchanged, to test_alembic_v2_report_revisions, which imports their revision IDs from the main module, as the household job revision module does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A one-year budget window is saved with null budget_window_years yet takes its budget-window run and refuses its year's run; moving a saved budget window to an economy report's run switches the stored current-run column; the /v2/me/export and admin saved-items reads pass a non-null current run through. They cover behaviour that already exists, so they pass before any change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new v2 revision must set each report's type from household_id and budget_window_size (a budget window stored as economy, or a report with no type, takes the type its columns give), then make reports.type required with ck_reports_type: economy, household or budget_window, matching those columns. The database then refuses a type that disagrees with the report. These tests fail until the revision exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A v2 revision (24b571d7d079) sets each stored report's type from its household_id and budget_window_size, then makes reports.type NOT NULL and adds ck_reports_type: economy, household or budget_window, agreeing with those columns. The data step is the hand-written one approved for D1 · 8; the operations are as generated. API v1 reads reports.type wherever it told report types apart from their columns (stored-report reads and re-runs, published-report runs), and removes report_kind and the unused set_report_type. A saved report's create or update reads the report it names once, through read_named_report, and checks its budget window and current run against that read. Tests and fixtures that store reports now give each its type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 found that the Alembic v2 check's script runs neither the report types revision's integration tests nor the report revision unit tests, so a regression in the data step or ck_reports_type could merge unnoticed. The workflow test now asserts the script lists both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mbic v2 check Review round 1 found two unit tests still expecting the old schema: the revision chain test named 7dcd2cd14330 as head, and the model test expected reports.type to be nullable. They now expect 24b571d7d079 and a required type. The Alembic v2 check's script now runs the report types revision's integration tests and the report revision unit tests. The Alembic guide gains a section for the revision (its data step, the order D1 · 7a and D1 · 9 deploy in), and names the module that now checks the earlier report revision files; the testing guide lists that module; the user-login document says when a saved report's write reads its report. The two test docstrings name the user's migration decision, as the revision does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cross-database integration check failed three cases of test_a_malformed_or_incomplete_key_is_refused: their reports had no type, so the database refused them for the required type before the key checks the test expects. The reports are now economy reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4400 +/- ##
==========================================
- Coverage 93.95% 93.93% -0.03%
==========================================
Files 459 459
Lines 26287 26285 -2
Branches 4070 4071 +1
==========================================
- Hits 24699 24690 -9
- Misses 902 909 +7
Partials 686 686
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Dec 4, 2026
anth-volk
marked this pull request as ready for review
December 4, 2026 18:15
anth-volk
added a commit
to PolicyEngine/policyengine-sim-api
that referenced
this pull request
Dec 4, 2026
PolicyEngine/policyengine-api#4400 merged as 57202c04, on API v1's master. Between its head 675e20f4, which this branch was tested against, and the merge commit, API v1 changes no v2 revision, privilege code or migration configuration, so the tables its chain builds are the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was previously deployed
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 #4399
Summary
Tracker task D1 · 8: every API v2 report names its type in
reports.type, and API v1 reads it.The revision. Revision
24b571d7d079, on7dcd2cd14330, is the new v2 head (V2_ALEMBIC_HEAD_REVISION). It runs a data step, then the generated operations.typefrom its columns:householdwhenhousehold_idis set,budget_windowwhenbudget_window_sizeis set, andeconomyotherwise. It updates only rows whose stored type differs. Until D1 · 7a, the simulation service stored a budget window aseconomy, and some reports have no type.reports.typebecomes NOT NULL;ck_reports_typeis added. It requires the type to be one of the three,householdexactly whenhousehold_idis set, andbudget_windowexactly whenbudget_window_sizeis set.The model.
Report.typeisReportType = Literal["economy", "household", "budget_window"], with the same check.API v1 reads the stored type. API v1 no longer works out a report's type from its columns:
report_kindandReportKindare removed. Stored-report reads, reads of a named run, run lists, re-runs and their cliff check, budget-window year reads (require_budget_window_year) and published-report run selection all readreports.type.set_report_typeandReportTypeImmutableErrorhad no callers and are removed.Saved-report writes read their report once. Creating or updating a saved report (
/v2/user-reports) reads the report it names once, through the new connectorread_named_report, which returnsNamedReport. The budget-window check and the current-run check both use that one read.report_id,budget_window_yearsorcurrent_run_id.budget_window_yearsorcurrent_run_idwithoutreport_idnow answers 404 if the saved report's own report isn't in its country. TheRESTRICTforeign key and the writes' country checks keep that from happening.docs/migration/stage-12a-user-login.mddescribes the read.Clean-up from D1 · 0a's review:
tests/unit/v2/test_alembic_v2_report_revisions.py, sotests/unit/v2/test_alembic_v2_revisions.pydrops from 1,465 to 1,242 lines.Also:
Report links are unaffected. A saved report's current run is still stored on the user-report association, whose ID is the report page's URL ID.
What the merge waits for
reportsrow. Until D1 · 7a is deployed, it stores a budget window aseconomy, whichck_reports_typerefuses. So the revision must not run in an environment before D1 · 7a is deployed there.D1 · 9 follows this PR. It updates the simulation service's model of
reports(the requiredtypeandck_reports_type) and moves its pinned API v1 commit. Until then, the simulation service's weekly comparison with this repository'smastertables reports both differences.This PR adds revision
24b571d7d079on7dcd2cd14330. #4396 (D2 · 3a) adds6ec3d17299b6on the same parent. Whichever merges second mergesmasterand moves itsdown_revisionto the other's revision. It does not build on another task's branch.Testing
Tests that fail before the change come first. All tests were run individually by node ID against a disposable PostgreSQL 17 database. No full suite was run.
9286d3f3moves the four report revision tests unchanged. They pass.74c120cdadds the four current-run tests. They pass on their first run, since they cover existing behaviour.9a1a5f71adds three tests that fail before the change, each on an assertion:test_report_types_revision_is_generated_with_one_approved_data_step(assert 0 == 1: no revision file);test_the_revision_sets_each_reports_type_then_requires_it(the revision isn't in the chain);test_the_database_refuses_a_type_that_disagrees_with_the_report(DID NOT RAISE IntegrityError).36c91cdais the change. The three tests pass, and so do the tests it edits: 15 in all. One test for each test helper whose report insert gained a type also passes: 14 in all.8a9df7b1adds the Alembic v2 check's two new script entries totest_reusable_v2_alembic_check_uses_only_disposable_postgres. It fails before the fix.682c2b04adds them to the script, after which the test passes. It also updates the chain and model tests, which expected the old head and a nullable type; both now pass.alembic -c alembic-v2.ini check("No new upgrade operations detected"),lint-imports,python -m scripts.rules validate,scripts/run_quality_guards.py, ruff,ruff format --checkand the configured mypy check.Review rounds
Round 1, on
36c91cda. Bugs found:type. Fixed.Its code-quality notes:
Round 2, on
682c2b04: no bugs. Its code-quality notes, all left:update_user_reportdoesn't mention the 404 above, and two comments attribute the window-size bounds tock_reports_typerather thanck_reports_budget_window_size.Bugs left: none.
Environment
This PR adds a test file to
.github/scripts/test_alembic_v2_lifecycle.sh, which thealembic-v2-checkworkflow runs. No environment variable is added or changed.V2_MIGRATION_DATABASE_URLalembic-v2-checkjob'senv:V2_ALEMBIC_DISPOSABLE_TESTalembic-v2-checkjob'senv:DEPLOYMENT_ENVIRONMENTtest🤖 Generated with Claude Code