Skip to content

Incorrect Event Triggering #24

@MafcoCinco

Description

@MafcoCinco

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 nil values

  • 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 c is placed into the db as a result of executing the first event

  • nil values should be stripped out of the input to event handlers in order to keep destructuring working correctly. The above schema causes a NullPointerException even though it contains an :or {c 0}. The reason for this is the input to the handler contains the key :c which has a value of nil. As such, the :or ... is not evaluated during destructuring and c retains a value of nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions