domino-clj / domino

A Clojure/Script data flow engine
https://domino-clj.github.io/
Eclipse Public License 1.0
177 stars 9 forks source link

Incorrect Event Triggering #24

Open MafcoCinco opened 4 years ago

MafcoCinco commented 4 years ago

In certain dependency configurations, events are not triggered properly. The below example is a simple schema that replicates the bug:

(def schema {:model [[:a {:id :a}]
                     [:b {:id :b}]
                     [:c {:id :c}]
                     [:d {:id :d}]]
​
             :events [{:inputs  [:a :b]
                       :outputs [:c]
                       :handler (fn [_ {:keys [a b]} _] {:c (+ a b)})}
                      {:inputs  [:a :c]
                       :outputs [:d]
                       :handler (fn [_ {:keys [a c] :or {c 0}} _] {:d (+ a c)})}]})

When the above schema is initialized and a transaction is executed with the following input:

(-> (domino/initialize schema) 
    (domino/transact [[[:a] 1] [[:b] 1]]))

there will be a NullPointerExecption. Furthermore, even if the second event handler is implemented to account for the fact that it could be called with a nil value of c, the correct output is never actually obtained as the handler is not invoked a second time when the db is updated with a new value for c (from the first event).

This highlights 3 issues:

yogthos commented 4 years ago

@SVMBrown fixed the issue by allowing the events to be executed multiple times. This will impact cases where event functions aren't pure, but that's not a supported or encourage use case at the moment. https://github.com/domino-clj/domino/commit/221fad440cb99e6e41b1431d383f1374089fab98