Repository navigation
Saved reports stop storing and returning a copy of the reform's changes - #4402
Merged
Merged
Conversation
…ailing) Saved reports no longer keep a copy of their reform's changes (`provisions`): pages read the report's policy and dynamic records. The tests expect: - `UserReportAssociation` to leave the `provisions` column unmapped, while the table keeps it, JSONB and nullable, until D1 · 10's revision drops it. - A save or an update to take the copy, which app v3 builds from before D1 · 5 still send, store none and leave a copy stored before untouched. - No read to return a copy: the owner's read and list, the shared read, the account export and the published report's saved-report fields. - OpenAPI to keep the request field, marked deprecated, and drop the response field. Rows saved before keep their copies; the tests store and read them through a class of their own that maps only the saved report's ID and the column. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Report pages read the report's policy and dynamic records, so a saved
report keeps no copy of its reform's changes (`provisions`):
- `UserReportAssociation` leaves the `provisions` column out of its
mapper (`exclude_properties`), declared in `__table_args__` so the
table keeps it. There is no revision: a release of this code keeps
serving while D1 · 10's revision drops the column, and rows saved
before keep their copies until then.
- `/v2/user-reports` saves and updates still take `provisions`, checked
as before, because app v3 builds from before D1 · 5 send it, and
discard it; OpenAPI marks the field deprecated. An update that sends
only that changes nothing.
- The owner's read and list, `/v2/shared-reports/{id}`, `/v2/me/export`
and published reports no longer return it.
The test fixtures stop building read records with the field, the
contract registry drops it from the response fields, and the generated
contract files are regenerated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UserReportAssociation declares user_report_associations.provisions as a Core column in __table_args__, which the api.data.orm-only rule reports. The ORM has no form for a column a table keeps but its class doesn't map, so the rule registry names it as a no-orm-form exception until D1 · 10's revision drops the column. The Alembic guide now says such a column needs the exception, and the update docstring, the request field's OpenAPI description and the changelog fragment describe what the code does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Alembic guide said an update through the model naming such a column raises AttributeError. A Session refuses it under its default synchronization but writes the column with synchronize_session=False, so the guide now says that what keeps the column unwritten is that no code names it. The simulation-role privilege tests' notes that no model leaves a column out now speak only of the simulation tables, and the request field's OpenAPI description says the value is checked, then discarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ailing) Review round 3: the decision of 2026-11-24 keeps a column awaiting removal as a SQLModel field that exclude_properties leaves out of the mapper, not as a Core column in __table_args__. In that form no update or insert through UserReportAssociation can name provisions, whatever its synchronization; the model test reads the column's PostgreSQL type from the field; and DIRECT_SQLALCHEMY_EXCEPTIONS lists columns_left_out_of_the_mapper again, as it did for C1 · 51a. All four runs fail on assertions against the Core-column form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3: the decision of 2026-11-24 (93e3be3) and C1 · 51a keep a column awaiting removal as a SQLModel field that exclude_properties leaves out of the mapper. UserReportAssociation now does so for provisions, with the declaration it had before, instead of a Core column in __table_args__. So no update or insert through the model can name the column, the rule api.data.orm-only needs no exception (removed from the registry, and rules.md regenerated), and DIRECT_SQLALCHEMY_EXCEPTIONS lists columns_left_out_of_the_mapper again. The Alembic guide's "Columns a mapper leaves out" is as before, naming this column and that inserts are refused too; the schema-reading helper loses declared_column; and the simulation-role privilege tests' docstring says again that such a column has no statement through the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4402 +/- ##
==========================================
- Coverage 93.95% 93.94% -0.01%
==========================================
Files 459 459
Lines 26287 26261 -26
Branches 4096 4088 -8
==========================================
- Hits 24697 24670 -27
- Misses 903 907 +4
+ Partials 687 684 -3
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 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 #4401
Summary
Saved reports (
user_report_associationsrows, served by/v2/user-reports) kept a copy of their reform's changes in the JSONB columnprovisions. With app v3 change D1 · 5, report pages, "Edit in Build", re-runs and shared links read the report's policy and dynamic records instead, so API v2 stops storing and returning the copy. This is the first of two steps (tracker task D1 · 5a):UserReportAssociationkeepsprovisionsas a SQLModel field, with its declaration unchanged, andexclude_propertiesleaves it out of the mapper. API v1 neither loads nor writes the column: no update or insert through the model can name it. The table keeps the column, so there is no Alembic revision andalembic -c alembic-v2.ini checkfinds no difference. Rows saved before keep their copies, which nothing reads. This is the form used for columns awaiting removal since 2026-11-24 (93e3be3b, C1 · 51a), which ruleapi.data.orm-onlyaccepts without an exception.DIRECT_SQLALCHEMY_EXCEPTIONSlistscolumns_left_out_of_the_mapperagain.POST /v2/user-reportsandPATCH /v2/user-reports/{id}still acceptprovisions, checked as before (the strict provision models, the 64 KiB limit, finite numbers), and discard it. App v3 tabs running builds from before D1 · 5 still send it. OpenAPI marks the request field deprecated. A PATCH that sends onlyprovisionssucceeds and changes no stored field exceptupdated_at.provisions: the owner's read and list (/v2/user-reports),GET /v2/shared-reports/{id},GET /v2/me/export,GET /v2/admin/users/{user_id}/saved-itemsand published reports' saved-report fields.ReportProvisionItemandReportProvisionIntervalItemleave the OpenAPI schema.docs/migration/stage-12a-user-login.md, the Alembic guide's "Columns a mapper leaves out" and aremovedchangelog fragment describe the change.The second step is tracker task D1 · 10, in a later release: an autogenerated revision drops
user_report_associations.provisions, the request models stop accepting the field, andcolumns_left_out_of_the_mapperleavesDIRECT_SQLALCHEMY_EXCEPTIONSagain, as C1 · 53 did. The two steps are separate because a release upgrades the v2 schema before the new Cloud Run revision takes traffic, so the previously deployed code, which maps the column, must keep working on the upgraded schema. The same split was used for the report columns (C1 · 40a, then C1 · 41) andparameter_values.dynamic_id(C1 · 51a, then C1 · 53).Migration scope
/v2/user-reports), shared reports (/v2/shared-reports/{id}), published reports (/v2/published-reports/{user_report_id}), the account export (/v2/me/export) and the admin saved-items read.provisions; the request field is deprecated, checked, then discarded.Testing
Each test was run individually by node ID.
tests/unit/v2/test_saved_report_reform_copy.py:synchronize_session=False) or insert through the model can nameprovisions.tests/unit/v2/test_models.py::test_saved_reports_keep_the_reform_copy_column_unmapped: the mapper leaves the column out; the table keeps it, nullable; the field declares JSONB on PostgreSQL. Tests read and write the unmapped column through a column-only class on a registry of its own (tests/unit/v2/saved_report_reform_copies.py).provisionsin responses;test_model_persistence.py::test_direct_sqlalchemy_categories_are_complete_and_documentedexpectscolumns_left_out_of_the_mapper;tests/integration/test_v2_user_identity_persistence.py::test_non_finite_numbers_never_reach_jsonbchecks nothing is stored.2467d9c8(tests): 14 of the 16 changed unit tests failed on assertions; the 2 that passed are rewrites of existing tests whose behaviour doesn't change. The integration test failed on its assertion (disposable PostgreSQL 17).b9de8730(change): the 17 changed unit tests (the 16 plus the admin saved-items test, whose fixture changed) and the integration test passed.73836ce3and040d4302: review rounds 1 and 2's fixes.5882f4b5(tests, review round 3): the statement test's two cases, the model test and the category test failed on assertions.400102be(change): 23 test runs passed. They are the changed tests above and the ORM-only rule teststest_database_code_uses_only_the_orm,test_orm_only_exceptions_match_a_finding_and_name_a_categoryandtest_every_table_is_mapped_by_a_class. The integration test passed too.alembic -c alembic-v2.ini checkon PostgreSQL 17 at head: no new upgrade operations.ruff check,ruff format --checkand mypy. mypy reports no new errors:associations.pyhas the sixField(sa_type=...)errorsmasterhas.lint-imports,python -m scripts.rules validateandguard, andpython scripts/run_quality_guards.py.scripts/export_migration_contracts.pyregenerated the contract files.No
# noqasuppressions are added.Review
Three rounds of adversarial review, each by a fresh reviewer in its own clone:
b9de8730): one high-priority bug. The enforced ruleapi.data.orm-only's testtest_database_code_uses_only_the_ormfailed on a Coresa.Column("provisions", ...)inUserReportAssociation's__table_args__.73836ce3first declared it as a rule exception, and400102belater replaced that with the field form (round 3). Wording notes on the update docstring, the request field's OpenAPI description and the changelog fragment were fixed in73836ce3.73836ce3): no bugs. Three low-priority wording notes were fixed in040d4302.73836ce3..040d4302): no bugs. It raised one medium-priority point outside its diff: the decision of 2026-11-24 keeps a column awaiting removal as a SQLModel field left out of the mapper, not as a Core column. That form also refuses every update and insert through the model that names the column.5882f4b5and400102befollow that decision, which also settles round 3's low-priority note on the guide's wording. They came after the third and last round, so no review round covered them.Bugs left: none.
Merge order
Earlier tasks in the tracker and what each must reach before this merges:
provisionsfrom these responses. Deploying this first would show no reform changes on saved reports and make re-runs refuse.This PR branches from
masterand builds on no other task's branch.🤖 Generated with Claude Code