Repository navigation
Stop mapping parameter_values.dynamic_id in API v1, keeping the column - #4353
Merged
anth-volk merged 5 commits intoNov 27, 2026
Merged
Conversation
…iling) API v1's ParameterValue is to leave dynamic_id out of its mapper, and no API v1 statement is to name the column, while the table keeps it with its key, check and both partial indexes. New tests check the mapper and the table, a whole-row read, the policy insert, publication's insert, comparison, uniqueness check and pruning, and the current-law reads. They fail now because the model maps the column and the code names it. Tests that set or read the column through the model write it through ParameterValueWithDynamic, the column-only class C1 · 53 adds (copied verbatim from 3685235), or drop it where it only filtered, with C1 · 53's own edits where they apply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ParameterValue keeps dynamic_id as a SQLModel field with its foreign key,
and the single-owner check and both partial indexes stay in
__table_args__, so the table and alembic check don't change; there is no
revision. __mapper_args__ = {"exclude_properties": ("dynamic_id",)} leaves
the column out of the mapper, so a whole-row load selects it no more.
No API v1 statement names it any longer: the policy insert (POST
/v2/policies and the dual-write v1-to-v2 policy copy), the three
current-law reads of the metadata routes, publication's insert,
comparison and uniqueness check, and pruning. Since revision 7f7335f0eb31
no row has a dynamic_id, so dropping the filters changes no result. A
release of this code keeps serving while C1 · 53's revision drops the
column.
The privilege manifest's comment on pruning is updated; no grant changes.
The Alembic skill's C1 · 50 section and both pruning descriptions say so.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1's code-quality finding: ParameterValue uses exclude_properties again, so DIRECT_SQLALCHEMY_EXCEPTIONS, the complete list of direct-SQLAlchemy categories of the v2 models, should list "columns_left_out_of_the_mapper" again, as it did while the report columns were left out of their mappers (C1 · 40a). The test now expects it and fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ew round 1) Review round 1's code-quality findings: - DIRECT_SQLALCHEMY_EXCEPTIONS lists "columns_left_out_of_the_mapper" again, with C1 · 40a's text, since ParameterValue leaves dynamic_id out of its mapper. - The simulation role privilege tests' module docstring and their UNMAPPED_COLUMN_CLASSES comment said no model leaves a column out; they now say no model of the run tables does. - The Alembic skill's "Columns a mapper leaves out" names parameter_values.dynamic_id as the current case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_id mapping branch 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 #4353 +/- ##
==========================================
- Coverage 93.90% 93.88% -0.03%
==========================================
Files 432 432
Lines 24195 24196 +1
Branches 3752 3752
==========================================
- Hits 22720 22716 -4
- Misses 846 852 +6
+ Partials 629 628 -1
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:
|
anth-volk
marked this pull request as ready for review
November 27, 2026 15:01
anth-volk
deleted the
v2plan/c1-51a-stop-mapping-parameter-values-dynamic-id
branch
November 27, 2026 15:02
anth-volk
added a commit
that referenced
this pull request
Nov 27, 2026
…rop branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
added a commit
that referenced
this pull request
Nov 27, 2026
…_id drop branch 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 #4352
Summary
API v1 stops reading and writing
parameter_values.dynamic_id, while the table keeps it. This lets #4351 (C1 · 53) drop the column while this release serves.There is no revision. The table, its key to
dynamics,ck_parameter_values_single_ownerand both partial indexes don't change, andalembic -c alembic-v2.ini checkfinds no difference.Why a release of its own: API v1's release workflow upgrades the schema before the new release takes traffic, and a whole-row ORM load names every mapped column. So the release that serves while #4351's revision runs must not name the column. #4347 (C1 · 50) was to make this change, but merged without it. The release before this one (#4347's and #4349's code) maps the column, which still exists, so it serves safely until this one is promoted.
This must be in production before #4351 merges.
Changes
ParameterValuekeepsdynamic_idas a SQLModel field with its foreign key, as ruleapi.data.orm-onlyrequires, and__mapper_args__ = {"exclude_properties": ("dynamic_id",)}leaves it out of the mapper. This is how the report columns were left out of their mappers before revision4e30076d4b9f(Stop mapping the report columns the next v2 revision drops #4333).7f7335f0eb31no row has adynamic_id, so dropping the filters changes no result:POST /v2/policiesand the dual-write v1-to-v2 policy copy) no longer sets it;/v2/parameter-values, its item route,/v2/model-catalog/parametersand/v2/model-catalog/variablesfilter onpolicy_id IS NULLonly;privileges.pychanges.policy_id.Query plans
Checked with
query_planon PostgreSQL 17, with a synthetic catalog of 540,000 current-law values and 4,000 policy values, afterANALYZE. Withoutdynamic_id IS NULL, the reads can't useuq_parameter_values_canonical_parameter_start_date, whose condition namesdynamic_id:/v2/parameter-valuesbyparameter_id, by names, or a whole version on a dayix_parameter_values_parameter_period, filteringpolicy_id IS NULL(about the same cost)uq_parameter_values_canonical_parameter_start_date/v2/parameter-values/{id}pk_parameter_valuespk_parameter_values/v2/model-catalog/parametersand/variables(values by parameter name)uq_parameter_values_policy_parameter_start_date(policy_id IS NULL AND parameter_id = …)ix_parameter_values_parameter_periodix_parameter_values_parameter_period: 220 msOnly publication's uniqueness check gets slower: about three times, once per publication. Over production's few million rows that is a second or two in a seed job of 17 to 20 minutes. #4351 replaces the canonical index with
uq_parameter_values_current_law_parameter_start_dateonpolicy_id IS NULL, which serves it again. This PR changes no index.Testing
9e3a4a6b0), then the change (48d848c9b). Five new unit tests failed for the expected reason:dynamic_id, while the table keeps it with its key, check and both partial indexes;select(ParameterValue)names nodynamic_id;dynamic_id=None, since the ORM sends NULL for every mapped column without a default);parameter_values.dynamic_id;/v2/parameter-values, its item route and/v2/model-catalog/parametersname none.dynamic_id IS NULLfilters on its own makes its test fail (checked with scratch edits, reverted).ParameterValueWithDynamic(tests/integration/parameter_values_with_dynamics.py, a column-only mapped class on a registry of its own, the same file Drop parameter_values.dynamic_id, its single-owner check and its per-dynamic index #4351 adds), or drop the filter. Tests of the column, the check and the per-dynamic index stay, since they still exist.alembic -c alembic-v2.ini checkfinds no difference.reconcile_v2_privileges.py apply --create-missing-rolesandverify,lint-imports,python -m scripts.rules validate,run_quality_guards.py, ruff and ruff format pass. mypy on the changedpolicyengine_api/data/v2/files reports only thesa_typeoverload errors these files already had, none on a changed line.export_migration_contracts.pychanges nothing.ALTER TABLE parameter_values DROP COLUMN dynamic_idrun by hand (which also drops the check and both partial indexes, as Drop parameter_values.dynamic_id, its single-owner check and its per-dynamic index #4351's revision will), 36 PostgreSQL cases ran: publication, pruning and restoring, dynamics and the v1-to-v2 policy copy,/v2/parameter-values(list, item, current values),/v2/model-catalog/parametersand/variables, and policy creation. 33 passed. The other 3 failed only at a test helper's own read of the column throughParameterValueWithDynamic, after the service calls had succeeded; with that check removed they passed. A script created a policy, created it again (which reads its stored values as whole rows), and read it asGET /v2/policies/{id}andGET /v2/policiesdo: all succeeded. Withmaster's code, the same database fails those reads and the policy create withUndefinedColumn.549c81dce(failing test) and5ca9e3d55:DIRECT_SQLALCHEMY_EXCEPTIONSlistscolumns_left_out_of_the_mapperagain, and two docs that said no model leaves a column out are corrected.Deploy order
parameter_valuesrows with adynamic_idat 0 in staging and production.🤖 Generated with Claude Code