-
Notifications
You must be signed in to change notification settings - Fork 9
Description
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:
-
The documentation should be updated, provided it does not already contain this information, to indicate that event handlers can be called with partial input. Users should not assume that all data is populated and they may receive some
nilvalues -
The event processing code should be fixed such that the handler for the second event is invoked a second time when a new value of
cis placed into thedbas a result of executing the first event -
nilvalues should be stripped out of the input to event handlers in order to keep destructuring working correctly. The above schema causes aNullPointerExceptioneven though it contains an:or {c 0}. The reason for this is the input to the handler contains the key:cwhich has a value ofnil. As such, the:or ...is not evaluated during destructuring andcretains a value ofnil.