Skip to content

Commit

Permalink
fix: Shallow copy group_entities and person_entity when cloning TBS
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Oct 15, 2024
1 parent 3fc4308 commit 2b676e5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions policyengine_core/taxbenefitsystems/tax_benefit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ def clone(self) -> "TaxBenefitSystem":
"_parameters_at_instant_cache",
"variables",
"entities",
"person_entity",
"group_entities"
):
new_dict[key] = value

Expand All @@ -676,10 +678,19 @@ def clone(self) -> "TaxBenefitSystem":
variable_name: variable.clone()
for variable_name, variable in self.variables.items()
}

# Apply shallow copies to all relevant entities
new_dict["entities"] = [copy.copy(entity) for entity in self.entities]
new_dict["person_entity"] = copy.copy(self.person_entity)
new_dict["group_entities"] = [copy.copy(entity) for entity in self.group_entities]

# For all shallow-copied entities, set entity._tax_benefit_system to the new system
for entity in new_dict["entities"]:
entity.set_tax_benefit_system(new)
for entity in new_dict["group_entities"]:
entity.set_tax_benefit_system(new)
new_dict["person_entity"].set_tax_benefit_system(new)

return new

def entities_plural(self) -> dict:
Expand Down

0 comments on commit 2b676e5

Please sign in to comment.