[0.6.0 blocker] state: update inherited_vars and tracking dicts when adding vars #2822
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cached vars were not updated when depending on dynamically added vars, because the dependency tracking dicts update substate_var_dependencies based on whether the var is inherited and inherited_vars was not being updated (and not being updated recursively) when vars were added to the state.
Now when a var is added, push the var down into all substates as an inherited var, and recursively (depth-first) update all substate _computed_var_dependencies and _substate_var_dependencies in case any of them were depending on a var that gets added later in the initialization process.
I don't think dynamically added vars get used that much outside of dynamic route args, so this probably doesn't come up in the wild that often.
Repro code
Navigate to
http://localhost:3000/0
.and in the terminal (with some debug prints added by me)
with some additional prints added to
ImmutableComputedVar.__get__
, we can see that the problem is unable to determine where the dynamically addedarg_str
var is definedThe code is assuming the
state_where_defined
is the state where accessed because of missinginherited_vars
tracking.Clicking the plus should increment all numbers, but without this fix, the
arg_str
doesn't get rendered correctly when accessed through substates.Test case and updated implementation forthcoming.