fix: AmbiguousRuleException bug caused by weak ordering of rules #1124
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.
Link to the issue: #1106
Bug description on StackOverflow: https://stackoverflow.com/questions/68514884/ambiguousruleexception-when-there-is-no-ambiguity
Description
The AmbiguousRuleException is being thrown whenever there is no ambiguity. This behaviour is not deterministic, and there is no simple way to predict whether the invocation of the pipeline would produce this error.
The actual problem is incorrect algorithm of rule selection out of the list of possible producers. This list is being sorted, but there is no strict order of the rules unless explicitly specified by
ruleorder
. The rule that has no explicitruleorder
is neither greater nor smaller than other rules, and the result of sorting such a list becomes incorrect. Consider three rules: smallest, neutral, greatest. There is an explicitruleorder: greatest > smallest
. That means that:That the result of
sorted([smallest, neutral, greatest])
would be[smallest, neutral, greatest]
while the result ofsorted([greatest, neutral, smallest])
would be[greatest, neutral, smallest]
, which is obviously incorrect.This commit addresses the issue and changes the logic of producer selection removing the dependency on the result of incorrect sorting.
QC
The changes cannot be verified with a deterministic test case because the issue depends on the random order of rules processing. Anyway, the change shall not break other test cases.
docs/
) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).