diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29b..a9e3f5ba 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: patch + changes: + fixed: + - Bug in labour supply responses. diff --git a/policyengine_core/simulations/simulation.py b/policyengine_core/simulations/simulation.py index 1a4c5d09..a6b5579b 100644 --- a/policyengine_core/simulations/simulation.py +++ b/policyengine_core/simulations/simulation.py @@ -635,15 +635,20 @@ def _calculate( return value if variable.requires_computation_after is not None: - if variable.requires_computation_after not in [ + variables_in_stack = [ node.get("name") for node in self.tracer.stack - ]: + ] + variable_in_stack = ( + variable.requires_computation_after in variables_in_stack + ) + required_is_known_periods = self.get_holder( + variable.requires_computation_after + ).get_known_periods() + if (not variable_in_stack) and ( + not len(required_is_known_periods) > 0 + ): raise ValueError( - f"Variable {variable_name} requires {variable.requires_computation_after} to be requested first. The full stack is: " - + "\n".join( - f" - {node.get('name')} {node.get('period')}, {node.get('branch_name')}" - for node in self.tracer.stack - ) + f"Variable {variable_name} requires {variable.requires_computation_after} to be requested first. That variable is known in: {required_is_known_periods}. The full stack is: {variables_in_stack}. {variable_in_stack, len(required_is_known_periods) > 0}" ) alternate_period_handling = False if variable.definition_period == MONTH and period.unit == YEAR: