Skip to content

ut_hb210_s2 cannot be passed as reform= (VariableNameConflictError) #9844

Open

Description

@MaxGhenis

ut_hb210_s2 cannot be passed as reform=:

from policyengine_us.reforms.states.ut.ut_hb210_s2 import ut_hb210_s2
from policyengine_us.system import CountryTaxBenefitSystem

CountryTaxBenefitSystem(reform=ut_hb210_s2)
VariableNameConflictError: You've already defined ut_hb210_s2_marriage_credit in None. You tried to define it again in None.

This was run on the head of #9628 (743b6dfd3d, which is main at ea79c39fb7 plus that PR).

Cause

CountryTaxBenefitSystem.__init__ applies the reform it is given twice:

  1. it applies it in if reform:, before structural-reform detection;
  2. it applies it again, together with the structural reforms, after the modified flags are reset.

main does the same. ut_hb210_s2's apply calls self.add_variable(ut_hb210_s2_marriage_credit) (policyengine_us/reforms/states/ut/ut_hb210_s2.py), so the second application finds the variable already defined. Simulation(reform=...) builds the system the same way, through spm.py.

One fix is to skip the add_variable when the variable already exists. The test in #9628 guards a parameter it adds in the same way. Found while reviewing #9628, which does not change this.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions