leonoel / missionary

A functional effect and streaming system for Clojure/Script
Eclipse Public License 2.0
620 stars 25 forks source link

Odd interaction with xtdb #66

Open nivekuil opened 2 years ago

nivekuil commented 2 years ago
(def test-node (xt/start-node {}))
(xt/submit-tx test-node [[::xt/put {:xt/id {:foo "1"}}]])

;; correctly returns the entity
(xt/entity (xt/db test-node) {:foo "1"})

;; returns nil?!
(y/? (y/sp (xt/entity (xt/db test-node) {:foo "1"})))

This only seems to happen when the :xt/id is a map, so it could be something odd on the XTDB side as well. Any ideas? repro: https://github.com/nivekuil/missionary-xtdb-repro java version is 17 (graalvm), clojure 1.11.1

leonoel commented 2 years ago

The issue seems related to type hints. sp tags forms with inferred types, confusing xtdb somehow. Here is a xtdb-only minimal repro :

;; incorrectly returns nil
(xt/entity (xt/db test-node) ^clojure.lang.PersistentArrayMap {:foo "1"})

A possible workaround could be to move the eid outside of the sp block to prevent tagging :

;; correctly returns the entity
(def eid {:foo "1"})
(y/? (y/sp (xt/entity (xt/db test-node) eid)))
nivekuil commented 2 years ago

Ah, I think I know what problem it is.. xtdb's nippy usage takes into account metadata so that type hint actually changes the document key for that entity. Reported previously here https://github.com/xtdb/xtdb/issues/1510. It's definitely a problem on xtdb's end, not sure there is anything to do for missionary.