ProcedureKit icon indicating copy to clipboard operation
ProcedureKit copied to clipboard

Bug evaluating NoFailedDependenciesCondition with NegatedCondition

Open martnst opened this issue 9 years ago • 5 comments

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.

martnst avatar Oct 13 '16 13:10 martnst

Hmm, interesting, I will have a think.

danthorpe avatar Oct 13 '16 15:10 danthorpe

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.

martnst avatar Oct 19 '16 09:10 martnst

Hi @martnst - I haven't had a chance to look into this properly yet - but will get to it. 👍

danthorpe avatar Oct 19 '16 10:10 danthorpe

No worries about timing, I just wanted to provide a possible solution.

martnst avatar Oct 19 '16 10:10 martnst

@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.

swiftlyfalling avatar Jan 30 '17 02:01 swiftlyfalling