Skip to content

Fix restore_simulation entity counts - #548

Open
Adelagric wants to merge 1 commit into
PolicyEngine:masterfrom
Adelagric:fix-restore-simulation-counts
Open

Adelagric wants to merge 1 commit into
PolicyEngine:masterfrom
Adelagric:fix-restore-simulation-counts

Conversation

@Adelagric

@Adelagric Adelagric commented Sep 10, 2026 •

Copy link
Copy Markdown

Fixes #547. Same defect and fix as openfisca/openfisca-core#1387, from which this module was forked.

restore_simulation rebuilt each group entity's count from members_entity_id (max + 1) and the persons' count from the members of the last group entity restored. A group entity with no member was silently dropped from the restored count while still listed in ids, so calculations on the restored simulation returned arrays with missing entities — or, when a value had been stored for the group entity, restoring failed with a ValueError. A tax-benefit system with no group entity at all could not be restored (UnboundLocalError).

Each entity's count is now restored from its own dumped ids, which also removes the person_count plumbing and the ordering constraint between the two restore passes.

Tests and checks run: two new tests in tests/core/test_dump_restore.py, both failing before the fix; full tests/ suite (698 passed — 3 pre-existing failures in test_yaml.py shell-script tests, environmental: the policyengine-core CLI is not on PATH in my sandbox, failing identically without this change); ruff format and ruff check clean; towncrier fragment added. Also run since opening: mypy --config-file mypy.ini on the two changed files — no issues. The full-codebase run reports 83 pre-existing errors in 20 untouched files (possibly stub-related in my minimal environment). Not run: make documentation.

Note on process: I don't have push access to the canonical repository, so this comes from a fork as offered in #547.

restore_simulation rebuilt each group entity's count from
members_entity_id (max + 1) and the persons' count from the members of
the last group entity restored. A group entity with no member was
silently dropped from the restored count while still listed in ids,
so calculations on the restored simulation returned arrays with
missing entities — or, when a value had been stored for the group
entity, restoring failed with a ValueError. A tax-benefit system with
no group entity at all could not be restored (UnboundLocalError).

Each entity's count is now restored from its own dumped ids, which
also removes the person_count plumbing and the ordering constraint
between the two restore passes.

Same defect and fix as openfisca/openfisca-core#1387, from which this
module was forked.

Fixes PolicyEngine#547

This branch has not been deployed

No deployments
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.

restore_simulation silently drops memberless group entities

1 participant