Repository navigation
Conversation
…list POST /v2/household-calculations is to accept `variables`, a list of the variables to calculate, for a stored household and for one given in the request. The tests cover its limits (at most 10,000 distinct names, not with add_missing_variables true, no empty name), the body sent to the simulation service (the list only when given), the check of each name against the running catalog version (a 422 with code unknown_variables naming the names it lacks, nothing checked when that version has no published catalog), and the OpenAPI document. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /v2/household-calculations takes `variables`, the variables to calculate instead of every variable add_missing_variables adds, for a stored household and for one given in the request. The list holds at most 10,000 distinct names, as the simulation service's household requests do, and is refused when given with add_missing_variables true. After the existing checks, each listed name is checked against the running catalog version, the catalog of the .py version API v1 runs, which policy parameters are checked against: names it lacks are refused with a 422 whose code is unknown_variables and which names them, sorted. When that version has no published catalog for the country, no names are checked. The simulation service is sent the list only when the caller gave one, so a calculation without it is accepted by every release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The simulation service's household contract takes variable names of at most 255 characters, so API v1 should refuse a longer listed name before sending it, not let the simulation service refuse it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ice does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A listed variable name holding a NUL character is to be refused as the caller's data, since PostgreSQL text can't hold NUL and the catalog query would otherwise fail as a storage outage (503). Also cover the variable check's 503 when the catalog can't be queried, and name the test of a list given with add_missing_variables true for what it asserts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PostgreSQL text can't hold NUL, so the catalog query failed on such a name and the calculation was answered 503, as for a storage outage. The request model now refuses it with a 422. Also: the migration doc lists the dynamic check and the variable check's 503 and says API v1, the household calculation session's docstring says API v1, and the changelog fragment says what the list does next to add_missing_variables and that names go unchecked when the running .py version has no published catalog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… limits Tests: an unknown household is answered 404 before its listed variables are checked, and an empty list is accepted and sent as given, for both request forms. The request and options docstrings (which the OpenAPI document shows) and the migration doc now give the per-name limit, the NUL refusal, the unpublished-catalog exception and what an empty list does, and the doc names the optional dynamic_id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4384 +/- ##
=======================================
Coverage 93.93% 93.93%
=======================================
Files 459 459
Lines 26219 26281 +62
Branches 4054 4069 +15
=======================================
+ Hits 24628 24688 +60
- Misses 905 908 +3
+ Partials 686 685 -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:
|
…bles branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rent pin A stored and an inline household calculation listing variables, and each with an empty list, are sent through the simulation service's generated client. On policyengine-api-simulation-client 0.20261201.454, whose request models have no variables field, send_request_with_body refuses before sending (ValueError naming variables); they pass once the pin is raised to the release with the field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ables policyengine-api-simulation-client 0.20261202.458, published by PolicyEngine/policyengine-sim-api#1177's release, has `variables` on its HouseholdCalculationRequest and InlineHouseholdCalculationRequest, so a household calculation that lists variables is sent through the generated client instead of being refused before sending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
December 2, 2026 16:26
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 #4382
Summary
POST /v2/household-calculationsacceptsvariables, the variables to calculate, so app v3's Household tab (PolicyEngine/policyengine-app-v2#1611) can ask for the roughly 330 variables it reads instead of every variableadd_missing_variables: trueadds. Tracker task D2 · 2b of "5. Detailed-save API".variablesis optional on both request forms, a stored household and a household given in the request. It holds at most 10,000 distinct names of 1 to 255 characters, the limits of the simulation service's request models in Calculate only the variables a household calculation lists policyengine-sim-api#1177. An empty list is accepted; null or an omitted field lists none. A repeated name, a name holding a NUL character, or a list given withadd_missing_variables: trueis refused with a 422 atvariables.codeunknown_variables, naming them sorted inunknown_variables(newV2UnknownVariablesErrorResponse), and nothing is sent. When the running .py version has no published catalog for the country, no names are checked. A catalog that can't be queried answers 503.variablesonly when the caller gave it, so a request without it is sent exactly as onmaster. Responses don't return the list; the simulation service keeps it in the job row'srequest_data.household_calculations/types.py;require_known_variablesandHouseholdCalculationVariablesUnknownErrorin its validators;read_variable_names, a new read in the metadata variables connector module (the runtime role already readsvariables); the check in the household calculation service, which now takesrunning_policyengine_versionas the policy service does; the route's 422; the body sent; docstrings;docs/migration/stage-11-v2-households.md;changelog.d/household-calculation-variables.added.md.Route groups covered:
/v2/household-calculations(FastAPI). Nothing changes on the Flask API v1 routes. User-visible contract change: the new optional request field and the new 422 refusal. No migration, no deployment change, no inline suppressions. It builds onmaster, not on an earlier task's branch.It raises the
policyengine-api-simulation-clientpin from0.20261201.454to0.20261202.458, the release PolicyEngine/policyengine-sim-api#1177's merge published, whoseHouseholdCalculationRequestandInlineHouseholdCalculationRequesthavevariables. On the old pin,send_request_with_bodyrefused before sending any body the generated model would drop, so a request listing variables could not be sent.uv.lockchanges only that package.Tests
New
tests/unit/v2/test_household_calculation_variables.py(request limits, the body sent, the check through the route on SQLite-backed services, OpenAPI) and two changed OpenAPI tests intests/unit/v2/test_household_calculation_routes.py. Each was run individually by node ID:0564ac15(tests before the change): 28 of 32 failed on assertions. The other 4 pass before the change as checks that existing behaviour holds: novariableskey is sent when none is given, and the route refuses a list withadd_missing_variables: true(onmasteras an unknown field).77a05735(the change): all 32 pass.b2552329then69443265: a 256-character name refused, failing on its assertion before the limit was set to 255, passing after.cca563adthen2a2cd274(review round 1): a name holding a NUL character refused, both forms, failing on assertions before the fix, passing after; the variable check's 503 when the catalog can't be queried, both forms, passing (covers existing behaviour).1ad1b3cb(after review round 2): an unknown household answered 404 before the variable check, and an empty list sent as given, both forms; passing (cover existing behaviour).ca98ba2fthen3f3c326d(the pin raise): a list of variables and an empty list sent through the generated client, for a stored and an inline household (cases intests/unit/libs/test_simulation_generated_client.py). On0.20261201.454the 4 cases failed withsend_request_with_body's ValueError namingvariables(raised before the test's assertions); on0.20261202.458they pass.Also run: the commit hook's
make quality(ruff, ruff format, the import contracts, mypy on 363 files,scripts/run_quality_guards.pyincluding file length) on every commit;python -m scripts.rules validate;scripts/export_migration_contracts.py(no file changed);alembic -c alembic-v2.ini checkon a disposable PostgreSQL 17 container (no new upgrade operations).Review
Two rounds of adversarial review (
policyengine-api-v2plan-d2-2b-household-calculation-variables-review-round<N>-2026-12-02.mdin the project's notes folder):69443265: 1 bug, low: a listed name holding a NUL character reached the catalog query, which PostgreSQL refuses, so the caller got a 503 instead of a refusal. Fixed in2a2cd274, test first. Also fixed: a test name that overstated what it asserts, the missing 503 test, the migration doc's list of checks (the dynamic check was missing), and the changelog wording.2a2cd274: no bugs. Its minor findings (tests of the check order and an empty list; docstrings and doc giving every limit) are addressed in1ad1b3cb, with no change in behaviour.Bugs left: none in this change. A NUL character in an inline
policyparameter name still answers 503, as it does onmaster; that is #4383.What the merge waits for
variablesand publishedpolicyengine-api-simulation-client0.20261202.458, which this PR pins.done), D2 · 1a (merged, enough: it changes only the staging timeout inpush.yml), and every task of substages A5 and C1.🤖 Generated with Claude Code