Bug fix: Backwards routing does not work when dependencies exist #1306
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.
What is the context of this PR?
Fixes an issue with backwards routing due to us overwriting the reference to
routing_path_block_ids
when building the path. The variablerouting_path_block_ids
is passed to_evaluate_routing_rules
by reference and mutated when routing backwards, however when dependent block ids exist, this reference is lost as we were re-assigning the variable: https://github.com/ONSdigital/eq-questionnaire-runner/blob/main/app/questionnaire/path_finder.py#L178-L181This change ensures the reference is not overwritten, but instead we use a new variable and a copy of
routing_path_block_ids
. In future, we will look at rewriting pathfinder to not do such mutation which not only is unclear but prone to error as proven by this.The updated schema simply moves the Confirmation question into the second section, which creates a when rule dependencies given the confirmation question's routing uses the first question. The additional dependencies are now populated because it is now in another section, previously it didn't need additional dependencies as it was part of the same routing path.
How to review
main
.No I need to correct this
Since the issue is with a memory reference being overwritten, no new tests were needed other than updating the schema and changing some section ids in the existing test. You can ensure that the existing unit test
test_remove_answer_and_block_if_routing_backwards
is adequate but running this schema and unit test onmain
and you should see that the test fails as the routing paths do not match.Checklist