Skip to content

fix(compiler): read a family a declared composite sums as one measure - #198

Merged
jm-rivera merged 2 commits into
devfrom
fix/composite-family-reading
Nov 14, 2026
Merged

jm-rivera merged 2 commits into
devfrom
fix/composite-family-reading

Conversation

@jm-rivera

@jm-rivera jm-rivera commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

A Studio card ranking France's DAC2a aid to recipients could not switch its provider to "net bilateral plus imputed multilateral as published, by convention". In prod the switch failed with "a calculation was asked of data in a shape it cannot read". That option binds DAC2a's stacked composite, whose two StatVars (aid type 206 and the gross imputed line 106) dfo-apis adds by declaration. Every slot is bound, so the compiler saw two StatVars and no axis to sum over, read them separately, and planner.shapes._rejects_rank refused a ranking over two measures. A fresh plan on that option failed the same way unless it stated stat_vars: "sum". DevelopmentFinanceObservatory/apis#304 serves the fact the mint acts on; this PR reads it.

Changes

  • SelectedSource.sums_components (new, hashed only when set) comes from resolved.stat_vars.sums_components in compiler.sources.source_from_spec_block. Only a JSON true sets it.
  • compiler.sources.default_reading reads a family summed when it has no open axis that cannot be summed and either has open axes or carries sums_components. _check_summable is unchanged, so an open unsummable axis, such as an expanded aid type, still reads separately. The plan card's reading clause now says the family is "summed over whichever of its 2 indicators hold data by default".
  • PlannerAdapter._revision_refused logs plan revision refused with the refusal code, the compile issue code (constraint) and the compiler's own reason cut to 500 characters, before the reason is reworded for the user. User-facing text is unchanged.

Notes for reviewers

The fix takes effect once apis#304 deploys. Until then the flag is absent and every family reads as today. The fixtures are the blocks apis serves for the DAC2a and CRS inclusive answers, captured from apis#304's tests. The ranking tests open the recipient on a copy, and that edit is stated in each docstring.

Testing: test_family_reading.py covers the DAC2a block summed by rule and a rank over recipients compiling with SUM. It also pins the unchanged cases: no flag still refuses input_shape_unsupported, an expanded aid type stays separate, and CRS inclusive reads summed either way. test_graph.py runs switch._switched_plan from a bilateral DAC2a ranking card to provider:inclusive through the real revise, translate and compile; before the change it reproduces the prod error. test_planner_adapter.py asserts the new log record's code and detail. Targeted harness suites pass (1,526 passed, 1 xfailed), with ruff and ty.

A plan card ranking France's DAC2a aid to recipients could not switch to "net bilateral plus imputed multilateral as published, by convention": the compiler read the composite's two StatVars as two measures and refused the ranking with `input_shape_unsupported`. dfo-apis adds a stacked composite's components by declaration and now says so in `resolved.stat_vars.sums_components`. `source_from_spec_block` carries the flag onto `SelectedSource.sums_components`, and `default_reading` reads such a family summed unless an open axis cannot be summed. A block without the flag reads as before.

A refused plan revision now logs its code and the compiler's raw detail before the reason is reworded for the user, so a refused switch can be diagnosed from the logs.
…reason only

The detail dict can hold several issues naming the user's entities. The log keeps what diagnosis needs: the refusal code, the compile issue code and the compiler's reason, cut to 500 characters.
@jm-rivera
jm-rivera merged commit 809c821 into dev Nov 14, 2026
10 checks passed
@jm-rivera
jm-rivera deleted the fix/composite-family-reading branch November 14, 2026 13:14
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.

1 participant