Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datomic: `:db.error/tempid-not-an-entity` tempid used only as value in transaction

When I try to transact this entity using a string tempid against datomic-free v0.9.5656, I get the following exception:

(def tx1 {:db/id             "user"
          :contact/full-name "John Wayne"})
(def tx2 {:db/id    "other"
          :some-ref "user"
(let [!rx (d/transact conn [tx2])]
   (prn (:tempids @!rx))
=> 

datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/tempid-not-an-entity tempid used only as value in transaction
    data: {#object[clojure.lang.Keyword 0x74af59e7 ":db/error"] #object[clojure.lang.Keyword 0x57972b49 ":db.error/tempid-not-an-entity"]}
             java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: :db.error/tempid-not-an-entity tempid used only as value in transaction

The documentation shows I should be able to use strings as tempids. Am I missing a reader macro to tell it about a partition?

like image 745
Petrus Theron Avatar asked Mar 14 '18 13:03

Petrus Theron


2 Answers

Turns out I was referring to a tempid of an entity that I was not included in the transaction.

I wish the error was clearer, e.g. "You refer to tempid 'user', but the only tempids in this tx are: #{"other"}" And then I'd spot the error immediately.

like image 102
Petrus Theron Avatar answered Nov 10 '22 02:11

Petrus Theron


Another way to get this error message is if you set an attribute to an empty vector. Presumably [] is being interpreted as a tempid, and there's no corresponding :db/id [] to be found in the transaction. Similar reasoning for an empty map {} - where's the tempid in the transaction with value {}?

like image 25
Chris Murphy Avatar answered Nov 10 '22 04:11

Chris Murphy