This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-30
Channels
- # aleph (2)
- # announcements (8)
- # babashka (12)
- # beginners (34)
- # calva (36)
- # cherry (3)
- # cider (1)
- # clj-kondo (11)
- # clj-otel (6)
- # cljdoc (31)
- # clojure (121)
- # clojure-conj (1)
- # clojure-czech (2)
- # clojure-europe (109)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (3)
- # cursive (3)
- # datahike (1)
- # datomic (9)
- # deps-new (6)
- # docker (5)
- # emacs (21)
- # fulcro (4)
- # hoplon (16)
- # introduce-yourself (2)
- # london-clojurians (5)
- # lsp (87)
- # malli (17)
- # missionary (1)
- # nbb (27)
- # off-topic (257)
- # pathom (4)
- # portal (42)
- # practicalli (1)
- # rdf (3)
- # releases (2)
- # shadow-cljs (49)
- # slack-help (3)
- # timbre (2)
I’m trying to update the value of an enum attribute using :db/cas
, but I keep getting the error message :db.error/cas-failed Compare failed
. Here’s an example of the transaction I’m trying to run:
(d/transact conn [[:db/cas [:order/id 1] :order/status :order.status/created :order.status/placed]])
;; OR
(d/transact conn [[:db/cas [:order/id 1] :order/status [:db/ident :order.status/created] :order.status/placed]])
How can I correctly update the value of the :order/status
attribute using :db/cas
?I think you should be using entity-ids instead of the keywords. Iirc Datomic will not resolve the keywords into their eids while using cas
The exception should contain :v
, and :v-old
m, presumably, :v
contains an long (eid) and :v-old
, contains a keyword. Which aren’t the same value; so the comparison fails
[:db/cas [:order/id 1] (d/entid db :order.status/created) (d/entid db :order.status/placed)] I opened an issue back in ~2016 asking a fix for it. The bug-tracker that I opened this issue does not exists anymore. 😞
Pulling the entity ID of the enum values works. Thanks! It is, however, counterintuitive. Anyway, I won’t hold my breath waiting for a fix.
The lack of generalized support for lookup refs bites me frequently too. It is especially frustrating in the context of composite tuples and refs (see https://gist.github.com/robert-stuttaford/e329470c1a77712d7c4ab3580fe9aaa3 for more discussion on that subject).
By default a lookup ref should be acceptable anywhere an entity id is accepted (query, pull, transact, cas, …). Exceptions should be prominently documented That ^ was once an expectation. Then a wish. Now maybe a proposal? FWIW, I spent most of 2022 convinced tuples with refs were broken only to gradually realize that the real problem was trying to use them in combination with lookup refs.