asami icon indicating copy to clipboard operation
asami copied to clipboard

Asami fails to retract :id sometimes

Open holyjak opened this issue 2 years ago • 1 comments

In some cases Asami fails to retract the :id attribute:

I do

(d/transact conn [
 [:db/retract :a/node-78464 :id [:address/id #uuid "ffffffff-ffff-ffff-ffff-000000000001"]]
 [:db/retract :a/node-78464 :address/id #uuid "ffffffff-ffff-ffff-ffff-000000000001"]
 [:db/retract :a/node-78464 :a/entity true]
 [:db/retract :a/node-78464 :address/street "X St"]])

yet the transact's returned :tx-data only have 3, not 4 datoms, missing the first one with :id :

(#datom [:a/node-78464 :address/id #uuid "ffffffff-ffff-ffff-ffff-000000000001" 2 false]
 #datom [:a/node-78464 :a/entity true 2 false]
 #datom [:a/node-78464 :address/street "X St" 2 false])

The following test demonstrates the issue:

(deftest delete-ident
  @(d/transact *conn* {:tx-data [{:id [:test/id "existing-ident"]
                                  :test/id "existing-ident" ; <----- comment out to "fix" the test
                                  }]})
  (let [eid (d/q '[:find ?e . :where [?e :id [:test/id "existing-ident"]]] (d/db *conn*))]
    (write/retract-entity *conn* [:test/id "existing-ident"])
    (is (= nil (d/entity (d/db *conn*) [:test/id "existing-ident"])) "The entity is no more")
    (is (= '() (d/q '[:find ?e ?a ?v :where [?e ?a ?v] :in $ ?e] (d/db *conn*) eid)))))

; where write/retract-entity is:
(defn retract-entity [conn id]
  (d/transact
    conn
    (d/q '[:find :db/retract ?e ?a ?v :where [?e ?a ?v] [?e :id ?id] :in $ ?id]
         (d/db conn) id)))

Notice that if I either change the :id to something else or I change either the key or the value of :test/id "existing-ident" then the test will pass. So there is some collusion between the two.

holyjak avatar Jul 21 '22 23:07 holyjak

@quoll I'd be happy to work on fixing this, if you can point me to where you think the problem might be 🙏 It is making my code too complicated as it is.

holyjak avatar Mar 30 '23 14:03 holyjak