Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/saved-reports-drop-reform-copy.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Saved reports no longer store a copy of their reform's changes: `/v2/user-reports`, `/v2/shared-reports/{id}`, `/v2/me/export`, `/v2/admin/users/{user_id}/saved-items` and published reports no longer return `provisions`, and API v1 stops mapping `user_report_associations.provisions`. Rows saved before keep their copies, which nothing reads, until a later revision drops the column. Saves and updates still accept `provisions` from older app builds and discard it.
14 changes: 7 additions & 7 deletions docs/engineering/migration-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ Generated from `policyengine_api/migration_registry.py` and `tests/contract/regi

| Method | Path | Status | Route group | Required headers | Stable response fields |
| --- | --- | ---: | --- | --- | --- |
| `POST` | `/v2/user-reports?country_id=us` | 201 | `report` | `Authorization` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.provisions`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `GET` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `Authorization` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.provisions`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `POST` | `/v2/user-reports?country_id=us` | 201 | `report` | `Authorization` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `GET` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `Authorization` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `GET` | `/v2/user-reports?country_id=us` | 200 | `report` | `Authorization` | `status`, `message`, `result.items`, `result.offset`, `result.limit`, `result.has_more` |
| `PATCH` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `Authorization` | `status`, `message`, `result.item.id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.provisions`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.updated_at` |
| `PATCH` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `Authorization` | `status`, `message`, `result.item.id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.updated_at` |
| `DELETE` | `/v2/user-reports/{association_id}?country_id=us` | 204 | `report` | `Authorization` | |
| `POST` | `/v2/user-reports?country_id=us` | 201 | `report` | `PolicyEngine-Unauthenticated-User` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.provisions`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `GET` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `PolicyEngine-Unauthenticated-User` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.provisions`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `POST` | `/v2/user-reports?country_id=us` | 201 | `report` | `PolicyEngine-Unauthenticated-User` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `GET` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `PolicyEngine-Unauthenticated-User` | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.user_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `GET` | `/v2/user-reports?country_id=us` | 200 | `report` | `PolicyEngine-Unauthenticated-User` | `status`, `message`, `result.items`, `result.offset`, `result.limit`, `result.has_more` |
| `PATCH` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `PolicyEngine-Unauthenticated-User` | `status`, `message`, `result.item.id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.provisions`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.updated_at` |
| `PATCH` | `/v2/user-reports/{association_id}?country_id=us` | 200 | `report` | `PolicyEngine-Unauthenticated-User` | `status`, `message`, `result.item.id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.description`, `result.item.user_policy_id`, `result.item.baseline_user_policy_id`, `result.item.source_note`, `result.item.validation`, `result.item.budget_window_years`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.updated_at` |
| `DELETE` | `/v2/user-reports/{association_id}?country_id=us` | 204 | `report` | `PolicyEngine-Unauthenticated-User` | |
| `GET` | `/v2/shared-reports/{association_id}?country_id=us` | 200 | `report` | none | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.source_note`, `result.item.provisions`, `result.item.validation`, `result.item.budget_window_years`, `result.item.baseline_reform`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |
| `GET` | `/v2/shared-reports/{association_id}?country_id=us` | 200 | `report` | none | `status`, `message`, `result.item.id`, `result.item.country_id`, `result.item.report_id`, `result.item.legacy_report_id`, `result.item.name`, `result.item.source_note`, `result.item.validation`, `result.item.budget_window_years`, `result.item.baseline_reform`, `result.item.last_run_at`, `result.item.current_run_id`, `result.item.created_at`, `result.item.updated_at` |

### `user_account_v2`

Expand Down
10 changes: 6 additions & 4 deletions docs/engineering/skills/alembic-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,13 @@ and `refused(session, ...)`.
takes the Python value, such as `[2026]`, not its JSON text.
- **Columns a mapper leaves out**: a column kept in its table but left out of
the model's mapper (`exclude_properties`) until a revision drops it, as
`parameter_values.dynamic_id` was until revision `1c651058fac5`, and the
`parameter_values.dynamic_id` was until revision `1c651058fac5`, the
per-user and cliff columns of `reports`, `report_runs` and
`budget_window_runs` were until revision `4e30076d4b9f`, has no statement
through the model: `update(Model).values(column=...)` raises
`AttributeError`, a constructor value is never stored, and `Model.column`
`budget_window_runs` were until revision `4e30076d4b9f`, and
`user_report_associations.provisions` is until D1 · 10's revision drops it,
has no statement through the model: `update(Model).values(column=...)` and
`insert(Model).values(column=...)` raise `AttributeError` whatever their
synchronization, a constructor value is never stored, and `Model.column`
is the table's Core column, which the rule rules out even in a `select`. A
test that sets or selects one maps it on a column-only class of a registry
of its own, of the kind `tests.integration.privilege_statements` holds, and
Expand Down
7 changes: 0 additions & 7 deletions docs/generated/migration_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,6 @@
"result.item.user_policy_id",
"result.item.baseline_user_policy_id",
"result.item.source_note",
"result.item.provisions",
"result.item.validation",
"result.item.budget_window_years",
"result.item.last_run_at",
Expand Down Expand Up @@ -1197,7 +1196,6 @@
"result.item.user_policy_id",
"result.item.baseline_user_policy_id",
"result.item.source_note",
"result.item.provisions",
"result.item.validation",
"result.item.budget_window_years",
"result.item.last_run_at",
Expand Down Expand Up @@ -1242,7 +1240,6 @@
"result.item.user_policy_id",
"result.item.baseline_user_policy_id",
"result.item.source_note",
"result.item.provisions",
"result.item.validation",
"result.item.budget_window_years",
"result.item.last_run_at",
Expand Down Expand Up @@ -1281,7 +1278,6 @@
"result.item.user_policy_id",
"result.item.baseline_user_policy_id",
"result.item.source_note",
"result.item.provisions",
"result.item.validation",
"result.item.budget_window_years",
"result.item.last_run_at",
Expand Down Expand Up @@ -1311,7 +1307,6 @@
"result.item.user_policy_id",
"result.item.baseline_user_policy_id",
"result.item.source_note",
"result.item.provisions",
"result.item.validation",
"result.item.budget_window_years",
"result.item.last_run_at",
Expand Down Expand Up @@ -1356,7 +1351,6 @@
"result.item.user_policy_id",
"result.item.baseline_user_policy_id",
"result.item.source_note",
"result.item.provisions",
"result.item.validation",
"result.item.budget_window_years",
"result.item.last_run_at",
Expand Down Expand Up @@ -1389,7 +1383,6 @@
"result.item.legacy_report_id",
"result.item.name",
"result.item.source_note",
"result.item.provisions",
"result.item.validation",
"result.item.budget_window_years",
"result.item.baseline_reform",
Expand Down
20 changes: 10 additions & 10 deletions docs/migration/stage-12a-user-login.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ Concurrency on Postgres:
body-validation error is reported and before any service or database work,
which bounds what can be stored. Caller fields are also bounded:
`description` and `source_note` at 10,000 characters, report `provisions` at
64 KiB serialized, and the report `validation` snapshot at 500 calibration
64 KiB serialized (checked, then discarded, since D1 · 5a), and the report
`validation` snapshot at 500 calibration
matches and 200 scorecard programs, with bounded strings (64 to 1,024
characters). `provenance` was already bounded (enumerated fields and a
2,048-character `ref`). Every user-route float and JSON value also rejects
Expand Down Expand Up @@ -595,9 +596,8 @@ contract shared with `policyengine-app-v2`. The generated route inventory is in
A saved report's ID is its shareable link, so `GET /v2/shared-reports/{id}`
takes no credential and sits outside the authenticated user-report router. It
never provisions a user. Its item is `{id, country_id, report_id,
legacy_report_id, name, source_note, provisions, validation,
budget_window_years, baseline_reform, last_run_at, current_run_id,
created_at, updated_at}`:
legacy_report_id, name, source_note, validation, budget_window_years,
baseline_reform, last_run_at, current_run_id, created_at, updated_at}`:

- `user_id`, `user_policy_id`, and `baseline_user_policy_id` are left out;
the owner and the owner's saved reforms stay private.
Expand All @@ -609,9 +609,8 @@ created_at, updated_at}`:
budget window's budget-window run, as `GET /v2/reports/{id}?run_id=` takes
it. Only the owner sets it, saving the report or with `PATCH`; there is no
re-run from a shared link.
- Anyone holding the ID can read the report's name, source note, and
provisions. There is no shared list or search, and the owner routes stay
owner-scoped.
- Anyone holding the ID can read the report's name and source note. There is
no shared list or search, and the owner routes stay owner-scoped.

### Published reports

Expand Down Expand Up @@ -655,8 +654,8 @@ report the saved report names. Every route takes `country_id`.
can't be published (409). An edit sends at least one field, none as null.
- **The public read** answers the page's title (the saved report's name),
summary, author IDs, tags and content; the saved report's source note,
provisions, validation, budget window and the name of the reform it was
compared with; the version read and the versions a reader may open, each
validation, budget window and the name of the reform it was compared with;
the version read and the versions a reader may open, each
with its run's versions and when the page moved to it; and the report
with that version's run, as `GET /v2/reports/{id}?run_id=` answers it,
labelled with the title. The owner, the saved report's `description` (the
Expand Down Expand Up @@ -780,7 +779,8 @@ from the final SQLModel metadata. It has no post-generation corrections.
with, when not current law; the baseline's name is that reform's name, so no
label is stored), `source_note`, `provisions jsonb` (each provision may carry
optional `growth`, `growth_start`, `growth_base`, `growth_round_to` and
`growth_round` settings), `validation jsonb`, and `budget_window_years smallint`
`growth_round` settings; since D1 · 5a nothing reads or writes it, and D1 · 10
drops it), `validation jsonb`, and `budget_window_years smallint`
(the years of the budget window run with the report, from its year; NULL for
none, otherwise 2 to 75 by `ck_user_report_associations_budget_window_years`,
matching the economy route's limit).
Expand Down
15 changes: 14 additions & 1 deletion policyengine_api/data/v2/models/associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""

from datetime import datetime
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any, ClassVar, Optional
from uuid import UUID

import sqlalchemy as sa
Expand Down Expand Up @@ -314,9 +314,19 @@ class UserReportAssociation(TimestampedModel, table=True):
report, not its kind: a budget window's years are report runs of the
window, so only API v2's write check refuses one as its current run. Both
are null for a saved report with no current run yet.

A saved report keeps no copy of its reform's changes: its pages read the
report's policy and dynamic records. The table's ``provisions`` column,
where saved reports used to keep that copy, stays a SQLModel field, as rule
``api.data.orm-only`` requires of every column, and ``exclude_properties``
leaves it out of the mapper, so API v1 neither loads nor writes it: a value
given to the constructor is never stored, and the class attribute is the
table's column, not a value to read. A release keeps working while a later
revision (D1 · 10) drops it.
"""

__tablename__ = "user_report_associations"
__mapper_args__: ClassVar[dict[str, Any]] = {"exclude_properties": ("provisions",)}
__table_args__ = (
sa.UniqueConstraint(
"id",
Expand Down Expand Up @@ -408,6 +418,9 @@ class UserReportAssociation(TimestampedModel, table=True):
index=True,
)
source_note: str | None = Field(default=None, sa_type=sa.Text)
# In the table but left out of the mapper (``exclude_properties``) until a
# revision drops it: rows saved before keep their copy of the reform's
# changes, which nothing reads.
provisions: list[Any] | None = Field(default=None, sa_type=_jsonb_type())
validation: dict[str, Any] | None = Field(default=None, sa_type=_jsonb_type())
# Years in the budget window run with the report, from the report's year.
Expand Down
6 changes: 6 additions & 0 deletions policyengine_api/data/v2/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"Concurrent report idempotency requires a savepoint and bounded "
"IntegrityError recovery around the database uniqueness constraint."
),
"columns_left_out_of_the_mapper": (
"A column API v1 no longer uses stays a SQLModel field of its "
"table, left out of the mapper by exclude_properties, until other "
"writers have stopped and a later revision drops it; API v1 neither "
"loads nor writes it meanwhile."
),
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
report_item,
)
from policyengine_api.fastapi_routes.v2.user_reports.response_models import (
ReportProvisionItem,
ReportValidationItem,
SharedBaselineReformItem,
)
Expand Down Expand Up @@ -133,7 +132,6 @@ class PublishedSavedReportItem(StrictPublishedReportAPIModel):
"""The saved report's presentation: as a shared report shows it, without IDs."""

source_note: str | None
provisions: list[ReportProvisionItem] | None
validation: ReportValidationItem | None
budget_window_years: int | None
baseline_reform: SharedBaselineReformItem | None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ def build_v2_published_report_router(
"Needs no credential and never provisions a user. Returns the "
"published report by its saved report's ID: its title (the saved "
"report's name), summary, author IDs, tags and content; the saved "
"report's source note, provisions, validation, budget window and "
"the name of the reform it was compared with; the version read "
"report's source note, validation, budget window and the name of "
"the reform it was compared with; the version read "
"and the versions a reader may open (every version while "
"show_past_versions, else only the newest), each with its run's "
"versions and when the page moved to it; and the report with that "
Expand Down
Loading
Loading