Fork me on GitHub

hi, I'm new to clara and I'm having a bit of trouble understanding clara's durability. I'm serialize the data, storing the rule base separately. When I restore everything, insert new facts, and rules are not running again. Rules fire great if I use the original session. i.e. not the one that was restored. I have been looking at and my broken test is at Any suggestions would be awesome! thanks


@nickowsy from a quick glance over your test I see your original session has a custom :fact-type-fn. You’ll need to supply the same :fact-type-fn that the original function had when deserializing the rulebase. See the 2-argument version of deserialize-rulebase:


So something like (deserialize-rulebase session-serializer {:fact-type-fn your-fact-type-function})


The reason it is that way is that arbitrary Clojure function objects aren’t serializable, so you have to either impose some kind of restriction on the functions used that gives you serializability or require the user to handle it; we went with the latter


@wparker thanks a ton! makes total sense 🙂


Not sure if this question goes against the design of fact-based systems, but is there a way to "update" a fact? That is, say we insert ->Fact x, and then we insert ->Fact y, is it possible to only get a single Fact with updated value y in a query?


concrete example:

(-> (handle test-file test-action) (r/query fields-for :?formRef "/forms/aae-form"))
({:?formRef "/forms/aae-form",
  :?fieldRef "/forms/aae-form/data/order/reason",
  :?field #{#justice.rules.forms.FormField{:formRef "/forms/aae-form",
                                           :fieldRef "/forms/aae-form/data/order/reason",
                                           :descriptor {:type "VALUE",
                                                        :valueType "STRING",
                                                        :value "foo",
                                                        :constraints {:minLength 1, :required true}}}
            #justice.rules.forms.FormField{:formRef "/forms/aae-form",
                                           :fieldRef "/forms/aae-form/data/order/reason",
                                           :descriptor {:type "VALUE",
                                                        :valueType "STRING",
                                                        :value "",
                                                        :constraints {:minLength 1, :required true}}}}})
I'd like the query to return all FormField's with unique :fieldRef; so in the above example if I update the :descriptor :value from "" to "foo", I only want the single fact returned