Skip to content

Include each variable's quantity type in the country metadata - #3987

Draft
anth-volk wants to merge 1 commit into
masterfrom
feat/metadata-variable-quantity-type
Draft

anth-volk wants to merge 1 commit into
masterfrom
feat/metadata-variable-quantity-type

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #3986

Summary

  • GET /{country_id}/metadata now includes quantityType in each variable's description: "stock" for a balance or value at one point in time, "flow" for an amount over a period.
  • The value is policyengine-core's Variable.quantity_type. A model sets it explicitly (for example household_rental_property_value and household_vehicles_value in the US, mortgage_debt in the UK), or core defaults it: "stock" for yes-or-no, whole-number, list, text and date variables and for rates (unit /1), "flow" otherwise.
  • Why: Show the period each household money input covers policyengine-app-v2#1360 labels each money input in the household builder with the period the amount covers ("Annually") and leaves the label off stocks. Without this field, money stocks such as "Rental property value" are labelled "Annually".
  • Where: one entry in PolicyEngineCountry.build_variables (policyengine_api/country.py). The Flask route and the native FastAPI route both serve country.metadata, so both return the new field. Existing fields are unchanged.
  • No route, database, migration-contract or deployment change. python scripts/export_migration_contracts.py produced no changes.

Testing

  • New TestVariableQuantityType in tests/unit/test_country.py, written first and failing before the change (KeyError: 'quantityType'):
    • US and UK employment_income are "flow"; US household_vehicles_value and UK mortgage_debt are "stock"; US is_blind is "stock" (core's default for a yes-or-no variable);
    • every variable in every country has "stock" or "flow".
  • make format and ruff check on the changed files: clean.
  • python scripts/run_quality_guards.py: passed.
  • Local run of the make test suite (tests/to_refactor tests/unit tests/contract tests/integration/test_budget_window_in_flight_dedupe.py): 2,799 passed.
  • In the browser: with the app's household builder (Update PolicyEngine US to 0.716.2 #1360's branch) pointed at the staging Public API, and the metadata response given quantityType from this branch's US model, "Rental property value" shows no period label, while "Rent" and "Employment income" still show "Annually".

🤖 Generated with Claude Code

GET /{country_id}/metadata now describes each variable's quantity type as
quantityType: "stock" for a balance or value at one point in time, "flow"
for an amount over a period. The value is core's Variable.quantity_type,
which a model sets or core defaults. The app's household builder needs it
to leave the "Annually" label off money stocks such as rental property
value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.17%. Comparing base (1163955) to head (2ebac45).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3987       +/-   ##
===========================================
+ Coverage   46.17%   84.17%   +38.00%     
===========================================
  Files         239      255       +16     
  Lines       13987    15364     +1377     
  Branches     2272     2557      +285     
===========================================
+ Hits         6458    12933     +6475     
+ Misses       6958     1676     -5282     
- Partials      571      755      +184     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include each variable's quantity type (stock or flow) in the country metadata

1 participant