Repository navigation
Conversation
PATCH /v2/user-policies/{id} now accepts policy_id. Supplied alone, it
points the saved policy at that v2 policy and clears legacy_policy_id,
which no longer describes the saved content. Supplied with
legacy_policy_id, the two must name the same policy. The policy must
exist in the row's country. Without this, the app could not change the
parameters of a reform saved on v2 without deleting the row and losing
its ID, which reports link to.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
added this pull request to stack #3971
October 20, 2026 01:26
This was referenced Oct 20, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3968 +/- ##
===========================================
+ Coverage 46.17% 84.12% +37.94%
===========================================
Files 239 255 +16
Lines 13987 15378 +1391
Branches 2272 2558 +286
===========================================
+ Hits 6458 12936 +6478
+ Misses 6958 1683 -5275
- Partials 571 759 +188 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The route description, the request model and service docstrings, and the changelog fragment said that policy_id and legacy_policy_id "must name the same policy". The service can check that only when the v1 policy has a v2 copy from the Stage 10 mirror; otherwise it stores both references, exactly as creation does. Say that, and add the new PATCH policy_id behavior to the Stage 12A association notes, which still described only legacy_policy_id. Documentation-only change: no behavior changes, so no test can fail first. 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 #3965
Summary
PATCH /v2/user-policies/{id}acceptspolicy_id. Supplied alone, it points the saved policy at that v2 policy and clearslegacy_policy_id, which no longer describes the saved content. Supplied withlegacy_policy_id, both are stored, andpolicy_idmust be the v2 copy of that v1 policy when the Stage 10 mirror made one (the service cannot compare them otherwise, as on creation).policy_idthat differs from the v1 policy's v2 copy returns 400, as on creation. An explicitnullis refused (422).Why: once the app's v3 workspace saves reforms as
/v2/policiespolicies (PolicyEngine/policyengine-app-v2#1347), editing a reform's parameters creates a new v2 policy. Without this change the row would have to be deleted and recreated, which changes the saved reform's ID that report records reference (user_policy_id).This is part of plan group 1E (v3 metadata and saved reforms). It is the bottom of a three-PR stack; the two above it fill the v2 metadata gaps (the plan's item 1E-1).
API contract change
Additive: the PATCH request schema gains the optional
policy_idproperty (visible in/v2/openapi.json). Clearinglegacy_policy_idhappens only when a caller sendspolicy_idwithout it, which no existing caller does. Nothing calls this yet.What stays on the v1 routes
Everything: no v1 route or v1 data changes. Saved policies created through
legacy_policy_idbehave exactly as before.Testing
uv run pytest tests/unit/v2/test_user_policy_service.py tests/unit/v2/test_user_policy_routes.py tests/unit/v2/test_user_route_auth.py tests/contract -q: 138 passed. New tests: repointing to a v2 policy clears the v1 reference and calls no v1 check; repointing with both references keeps both; unknown, other-country and conflicting policies change nothing; the request model acceptspolicy_idand refusesnull; the route forwardspolicy_id; the OpenAPI schema lists it.tests/integration/test_alembic_v2_lifecycle.py tests/integration/test_v2_user_identity_persistence.py: 21 passed.docs/migration/stage-12a-user-login.md) describe the new PATCHpolicy_idbehavior.uv run --frozen --extra dev mypy: no issues.ruff formatandruff checkon changed files: clean.python scripts/run_quality_guards.py: passed.python scripts/export_migration_contracts.py: no changes.Merge order and deployment
Possible conflicts
The open ruff refactor PRs (#3920, #3924, #3932–#3934) may touch the user-policy service modules; whichever merges second rebases.
🤖 Generated with Claude Code