Skip to content

Run the UK contract's household route when country imports are skipped - #646

Closed
MaxGhenis wants to merge 2 commits into
mainfrom
fix/uk-contract-household-route-skip-flag
Closed

MaxGhenis wants to merge 2 commits into
mainfrom
fix/uk-contract-household-route-skip-flag

Conversation

@MaxGhenis

Copy link
Copy Markdown
Contributor

Fixes #645

What was wrong

scripts/check_uk_candidate.py sets POLICYENGINE_SKIP_COUNTRY_IMPORTS=1 at startup, which makes policyengine/__init__.py bind policyengine.uk = None. The contract's _WrapperHouseholdRoute._call reached the wrapper as pe.uk.calculate_household(...), so in the gates run every wrapper.household row raised AttributeError: 'NoneType' object has no attribute 'calculate_household'. Candidate 2.134.5-1.58.2 (#639) was rejected on exactly those 16 rows (15 errors, plus unknown_path's rejection check failing on the same error). No UK candidate could qualify through certify-uk-release.

Change

  • The route imports policyengine.tax_benefit_models.uk directly. It exposes the same calculate_household that policyengine.uk binds, and depends only on policyengine_uk being installed, not on the skip flag.
  • A regression test runs evaluate_case(april_rate_change, "wrapper.household") in a subprocess with the flag set. It first asserts policyengine.uk is None, so it exercises the failing condition, then requires no error rows.

Verification (local, Python 3.13, locked env: policyengine-uk 2.130.1)

  • The new test fails on main's route code with the production error ('NoneType' object has no attribute 'calculate_household') and passes with the fix (23 s).
  • tests/test_uk_budget_reform_contract.py in full: see the comment below once it finishes.
  • ruff format --check and ruff check pass on both changed files. Repo-wide ruff check exits 1 on main too with the local ruff, so that isn't from this change.

Invariant

For any caller environment, a wrapper.household row's status depends on the model's answer, not on whether POLICYENGINE_SKIP_COUNTRY_IMPORTS was set before policyengine was imported.

After merge

The next scheduled certify-uk-release run qualifies the newest pe-uk (2.134.7) on the fixed contract. Candidates #639 and #644 were staged on the old code, and the catch-up should supersede them.

🤖 Generated with Claude Code

scripts/check_uk_candidate.py sets POLICYENGINE_SKIP_COUNTRY_IMPORTS=1,
which binds policyengine.uk to None. The wrapper.household route reached
calculate_household through it, so every household row errored and every
UK candidate was rejected (2.134.5-1.58.2). Import the country module
directly; it exposes the same function regardless of the flag.

Fixes #645

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

Copy link
Copy Markdown
Contributor Author

Local verification at e820bef (Python 3.13, locked env: policyengine-uk 2.130.1): tests/test_uk_budget_reform_contract.py in full gives 122 passed in 4 min 3 s. The new test fails on main's route code with 'NoneType' object has no attribute 'calculate_household' and passes with the fix.

…hold-route-skip-flag

# Conflicts:
#	tests/test_uk_budget_reform_contract.py
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Merged main (#643) at 7fa30ea. The only conflict was both PRs appending tests at the end of tests/test_uk_budget_reform_contract.py, and both blocks are kept unchanged. The merged file gives 136 passed locally (3 min 22 s). The route change (e820bef) is untouched.

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #651, which W1 (owner of the contract runner) opened for the same root cause, with an equivalent fix and a stricter test (household rows must pass). This PR's CI was green at 7fa30ea (Test 3.11–3.14), and its local runs (136 passed on the merged file; the new test failed on main with the production error) corroborate #651's diagnosis. Issue #645 is the same bug as #650.

@MaxGhenis MaxGhenis closed this Oct 17, 2026
@MaxGhenis
MaxGhenis deleted the fix/uk-contract-household-route-skip-flag branch October 17, 2026 02:21
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.

UK reform contract: wrapper.household errors under the candidate script, so every UK candidate is rejected

1 participant