Fork me on GitHub
#datomic
<
2023-03-30
>
Henrique Prange01:03:40

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?

thumbnail05:03:37

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

thumbnail05:03:45

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

souenzzo13:03:51

[: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. 😞

Henrique Prange15:03:39

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.

2
cch118:04:30

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).

4
👍 2
Ivar Refsdal17:04:30

I've also been bitten by this too many times. :-/

👍 2
souenzzo17:04:43

I never saw the team comment on this 😞 not even a "wontfix" or anything like that.

cch118:04:22

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.