Bug evaluating NoFailedDependenciesCondition with NegatedCondition
I run into some edge case in which NoFailedDependenciesCondition to evaluate wrong. If I add a condition that is wrapped in a NegatedCondition.
let operation1 : Procedure = …
let operation2 : Procedure = …
let authorizedCondition : AuthorizedFor = ...
operation2.addDependency(operation1)
operation2.attach(condition: NegatedCondition(authorizedCondition))
operation2.attach(condition: NoFailedDependenciesCondition())
Now when operation1 finishes successfully and authorizedCondition evaluates with a negative result which should be turned into a positive by NegatedCondition operation2 still won't execute. After some debugging I found that the authorizedCondition results in a direct dependency of operation2 which failed and therefore lets the NoFailedDependenciesCondition also fail.
I guess this is a bad side effect of running the Conditions as Operations. I think the NoFailedDependenciesCondition should filter Operations that are Conditions during the evaluation.
Hmm, interesting, I will have a think.
Hi @danthorpe,
FYI: For now I patched it locally in NoFailedDependenciesCondition.swift#L43 as following:
- let dependencies = procedure.dependencies
+ let dependencies = procedure.dependencies.filter { ($0 as? Condition) == nil }
However there is probably a better way. As mentioned the issue comes from using Operations to evaluate Conditions. Maybe such operations should be filtered inside procedure.dependencies. Since I did not know what side effect changed procedure.dependencies might have I just fixed it inside NoFailedDependenciesCondition for now.
Hi @martnst - I haven't had a chance to look into this properly yet - but will get to it. 👍
No worries about timing, I just wanted to provide a possible solution.
@martnst: This should be fixed as part of a new Conditions PR (with many other Condition improvements). See #681, and branch feature/OPR-681_condition_improvements.