Fork me on GitHub
#datomic
<
2023-02-24
>
Drew Verlee01:02:18

In this https://www.opensourcery.co.za/2017/05/29/two-datoms-in-the-same-transaction-conflict/, i want to be clear, the error (below) happens because the same entity, which is unique identified by the membership/set-fee=10, in the transaction (the vector passed as the value to tx-value), is given two different instructions about what to st it's other values to. e.g :being/family-name =Malich OR Galder?

user=> (def wizards [{:being/given-name "Alberto"
                      :being/family-name "Malich"
                      :membership/number 10
                      :membership/set-fee 10
                      :membership/set-fee-justification 
                      "Wizard discount"}
                     {:being/given-name "Galder"
                      :being/family-name "Weatherwax"
                      :membership/number 11
                      :membership/set-fee 10
                      :membership/set-fee-justification 
                      "Wizard discount"}])
'user/wizards
user=> (<!! (client/transact conn {:tx-data wizards}))
{:datomic.client-spi/request-id "4c69f404-07a4-4c99-bdbb-4596c97ec1f1",
 :cognitect.anomalies/category :cognitect.anomalies/incorrect,
 :cognitect.anomalies/message ":db.error/datoms-conflict Two datoms in the same transaction conflict\n{:d1 [17592186045418 :being/given-name \"Alberto\" 13194139534313 true],\n :d2 [17592186045418 :being/given-name \"Galder\" 13194139534313 true]}\n",
 :dbs [{:database-id "59293380-3347-4675-be0a-7daa6286b41c", 
        :t 1006, 
        :next-t 1007, 
        :history false}]}
So then, the attribute (:being/given-name) from this error (from the blog):
db.error/datoms-conflict Two datoms in the same transaction conflict
{:d1 [17592186045418 :being/given-name \"Alberto\" 13194139534313 true],
 :d2 [17592186045418 :being/given-name \"Galder\" 13194139534313 true]}
could just have easily been :membership/number right? I feel like the error is highlighting the conflict but not the reason for it. Or i'm i missing something? Would it also be the case, that if those two hashmaps were put into two different transactions, there would be no error? I'm like 99% sure of this, i just want to confirm that's what i should expect. In that case, the name attribute Malich would be "replaced" with Galder.

Leaf Garland23:02:23

The map form of data in transactions is a convenience, they need to be converted to datoms. The resulting list of datoms then includes the conflicts that your error message shows but the context that those datoms were conflicting because both maps were for the same entity is lost at that point.

Leaf Garland23:02:01

In different transactions you can, of course, assert different values for an entity/attribute, so transacting the 2 map forms independently would work fine.

Drew Verlee23:02:06

Thanks leaf, so far that makes sense to me.

Leaf Garland23:02:42

I find it helpful to think about what the map forms in transaction data will look like as lists of datoms - as that is generally what Datomic 'speaks' (in error messages, etc.)

👍 2