Hi. I noticed something strange when storing data in the context re-using the same key. I lookup a value in :allowed? and store it in the ::instance key of the context. If it's a PUT I assoc the result of the update to ::instance and return it in :handle-ok. For some strange reason, this causes a duplication in the vector :children?
Here the boild down version of our code:
(defresource put-delete-get [system path id json-body {:keys [find-by-id find-versions
create update delete-by-id validation-fn
has-permission] :or {has-permission (constantly true)}}]
:allowed-methods [:put :delete :get]
:available-media-types ["application/json"]
:allowed? (fn [{{method :request-method} :request}]
{::instance (find-by-id system id)})
:exists? ::instance
:can-put-to-missing? false
:new? false
:respond-with-entity? (fn [{{method :request-method} :request}] (= :put method))
:put! (fn [ctx]
(let [old (get ctx ::instance)
new (update system json-body)]
(println "###### Old ######\n")
(clojure.pprint/pprint old)
(println "###### New ######\n")
(clojure.pprint/pprint new)
(assoc ctx ::instance new)))
...
:handle-ok (fn [ctx]
(println "####### Result ######")
(clojure.pprint/pprint (get ctx ::instance))
(get ctx ::instance)))
=>
###### Old ######
{:children ["51e7e7ab30043ff5187d568e"],
:_version 2}
###### New ######
{:children ["51e7e7ab30043ff5187d568e" "51e7e7b630043ff5187d5690"],
:_version 3}
###### Result ######
{:children
["51e7e7ab30043ff5187d568e"
"51e7e7ab30043ff5187d568e" <-- Duplicate!?
"51e7e7b630043ff5187d5690"],
:_version 3}
Is this a bug, or am I doing something stupid in my handlers?
Thanks
-Erik