Repository navigation
Take a dynamic on household calculations and household reports - #4343
Merged
Merged
Conversation
…s (failing) /v2/household-calculations and household reports are to accept a dynamic_id, check it in the request's country through the economy path's dynamic check, send it to the simulation service only when named, and map the simulation service's unknown_dynamic refusal as the economy path does. These tests fail until that change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
/v2/household-calculations and each side of a household report on /v2/reports accept an optional dynamic_id. It is checked as an economy simulation's dynamic is, through require_runnable_dynamics and the same DynamicSource as /v2/dynamics: 404 when the request's country does not store it, and 422 missing_parameters when it sets parameters the running catalog version lacks, after the policy checks. Each household report side keeps its own dynamic, as economy reports do. API v1 sends a named dynamic to the simulation service and leaves a null one out of the request body, so the simulation service's release before it took a household dynamic still accepts every request without one. The household calculation client answers the simulation service's 400 unknown_dynamic as the caller's error (422), as the report client already does. Household calculations answer the dynamic_id they apply, read from household_jobs.dynamic_id. Household report re-runs still send only the report, so the simulation service keeps each side's stored dynamic. The household calculation service now takes its countries, households, policies and dynamics sources as one HouseholdCalculationSources value, and the test helpers that build it change with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…country's dynamic (failing) From review round 1: the report create route's 422 description should name the simulation service's 400 for a dynamic, and the household calculation routes' 404 description should not say a calculation is read in a country. The database-backed household calculation route also refuses a dynamic stored for another country, and the household report re-run test says what it checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…und 1 found The report create route's 422 description names the simulation service's 400 for a region, dynamic or dataset. The household calculation routes' 404 description no longer says a calculation is read in a country. The household calculation route module and the resource service protocol name the dynamic and its refusals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4343 +/- ##
==========================================
- Coverage 93.84% 93.83% -0.01%
==========================================
Files 426 426
Lines 23839 23866 +27
Branches 3696 3703 +7
==========================================
+ Hits 22372 22395 +23
- Misses 848 852 +4
Partials 619 619
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:
|
…ehold dynamics branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
November 26, 2026 12:55
3 tasks done
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 #4342
Summary
/v2/household-calculationsand household reports take a dynamic (tracker task C1 · 45).Requests.
/v2/household-calculations(HouseholdCalculationInput) and each household report side (HouseholdPolicyChoice) accept an optionaldynamic_id.Checks. A named dynamic is checked with the economy path's own code,
simulation_service.services.require_runnable_dynamics, through the same dynamic service as/v2/dynamics:missing_parameterswhen it sets parameters the running catalog version lacks.Policies are checked first, then dynamics, baseline first. A failed dynamic read answers 503, as for policies.
Both sides. Each household report side keeps its own dynamic, and nothing requires the two to match, as for economy reports. The front end sends one dynamic on both sides.
Requests to the simulation service. A named dynamic is sent; a null one is left out of the body. The simulation service applies the dynamic (Household calculations and reports apply a dynamic, and every simulation refuses another country's dynamic policyengine-sim-api#1113).
Its refusals.
unknown_dynamicanswers 422.unknown_dynamicthe same way (422, with the service's code and reason). It used to answer every 400 as 503.dynamic_id(missing parameters, or a parameter both the policy and the dynamic set) pass through as 422.Re-runs. A household report re-run still sends only the report, so the simulation service reads and applies each side's stored dynamic. Dynamics aren't checked again on a re-run, as for economy reports.
Responses. Household calculation items (submitted and read) gain
dynamic_id, read fromhousehold_jobs.dynamic_id. Household report items already give each side'sdynamic_id.Structure.
V2HouseholdCalculationServicetakes its countries, households, policies and dynamics sources as oneHouseholdCalculationSourcesvalue; six keyword arguments would fail ruff'sPLR0913.No revision, grant, workflow or environment variable changes.
household_jobs.dynamic_idandsimulations.dynamic_idalready exist.Migration notes:
household(/v2/household-calculations) andreport(/v2/reports, household kind).dynamic_idrequest fields, and the requireddynamic_idin household calculation responses. The migration contract documents are regenerated.Deploy order
This PR merges after PolicyEngine/policyengine-sim-api#1113, once that sim release is deployed to production (the tracker order also puts C1 · 44 first). The simulation service's request models refuse unknown fields:
dynamic_idis left out, so they work.dynamic_idthemselves, so the simulation service never receives one. API v1 ignores the newdynamic_idin sim's job answers.No caller sends a dynamic yet: the front end's household pages will send one only from a later task.
Overlap with other API v1 pull requests
#4329, #4333, #4335 and #4337, which touched some of the same files, have all merged. This branch merged
master(888ae6118) ate063231fdwith no conflict. The migration contract documents regenerate unchanged, and this PR's 145 unit and 18 PostgreSQL cases still pass by node ID.Testing
household_jobs.dynamic_id.make quality(ruff, ruff format, Import Linter, mypy, quality guards),python -m scripts.rules validate,alembic -c alembic-v2.ini check(no new operations) andpython scripts/export_migration_contracts.py.🤖 Generated with Claude Code