Fork me on GitHub
#asami
<
2022-03-31
>
Jakub Holý (HolyJak)17:03:42

Obviously I do something very bad to my in-mem asami, as I end up with having -1 as the node id, while I expected this tempid to be mapped to a real ID (details in 🧵 )

Jakub Holý (HolyJak)17:03:00

I end up with these triplets:

([:a/node-59555 :com.fulcrologic.rad.test-schema.address/id #uuid"ffffffff-ffff-ffff-ffff-000000000001"]
 [:a/node-59555 :com.fulcrologic.rad.test-schema.address/street "A St"]
 [:a/node-59555 :db/ident :a/node-59555]
 [:a/node-59555 :a/entity true]
 [-1 :com.fulcrologic.rad.test-schema.person/id #uuid"ffffffff-ffff-ffff-ffff-000000000100"]
 [-1 :id [:com.fulcrologic.rad.test-schema.person/id #uuid"ffffffff-ffff-ffff-ffff-000000000100"]]
 [-1 :com.fulcrologic.rad.test-schema.person/full-name' "Bob"]
 [-1
  :com.fulcrologic.rad.test-schema.person/primary-address'
  [:id [:com.fulcrologic.rad.test-schema.address/id #uuid"ffffffff-ffff-ffff-ffff-000000000001"]]]
 [-1 :com.fulcrologic.rad.test-schema.person/role' :com.fulcrologic.rad.test-schema.person.role/admin]
 [[:id [:com.fulcrologic.rad.test-schema.address/id #uuid"ffffffff-ffff-ffff-ffff-000000000001"]]
  :com.fulcrologic.rad.test-schema.address/street'
  "A1 St"])

Jakub Holý (HolyJak)17:03:23

I have transacted

[[:db/add
  -1
  :com.fulcrologic.rad.test-schema.person/id
  #uuid "ffffffff-ffff-ffff-ffff-000000000100"]
 [:db/add
  -1
  :id
  [:com.fulcrologic.rad.test-schema.person/id
   #uuid "ffffffff-ffff-ffff-ffff-000000000100"]]
 [:db/add -1 :com.fulcrologic.rad.test-schema.person/full-name' "Bob"]
 [:db/add
  -1
  :com.fulcrologic.rad.test-schema.person/primary-address'
  [:id
   [:com.fulcrologic.rad.test-schema.address/id
    #uuid "ffffffff-ffff-ffff-ffff-000000000001"]]]
 [:db/add
  -1
  :com.fulcrologic.rad.test-schema.person/role'
  :com.fulcrologic.rad.test-schema.person.role/admin]
 [:db/add
  [:id
   [:com.fulcrologic.rad.test-schema.address/id
    #uuid "ffffffff-ffff-ffff-ffff-000000000001"]]
  :com.fulcrologic.rad.test-schema.address/street'
  "A1 St"]]
I am sure it is my mistake, must explore...

quoll18:03:31

I'm not sure how the subjects of

[:id
   [:com.fulcrologic.rad.test-schema.address/id
    #uuid "ffffffff-ffff-ffff-ffff-000000000001"]]
will be handled. That's a bit unusual, and I haven't considered anything like that

quoll18:03:29

I expected node-refs to be in entities (represented as maps), and not in :db/add statements. And when I don't define something, then the actual behavior is undefined, meaning that anything could happen 🙂

quoll18:03:54

Hmmm, I do see one problem. You're creating an entity with a :db/id of -1 (which should work, I hope!) and then add other attribute/values to it. But then you try to reference it with: [:id [:com.fulcrologic.rad.test-schema.address/id #uuid "ffffffff-ffff-ffff-ffff-000000000001"]] That tells the transactor to look up a node that has that as an id. But... there IS no node that has that as an ID. You're still creating it, so it doesn't exist yet. It won't exist until the end of the transaction

quoll18:03:36

Maybe this would work?

[{:db/id -1
  :com.fulcrologic.rad.test-schema.person/full-name "Bob"
  :com.fulcrologic.rad.test-schema.person/role :com.fulcrologic.rad.test-schema.person.role/admin
  :com.fulcrologic.rad.test-schema.person/primary-address {
    :db/id -2
    :com.fulcrologic.rad.test-schema.address/street "A1 St"
  }
 }
 [:db/add
  -1
  :id
  [:com.fulcrologic.rad.test-schema.person/id
   #uuid "ffffffff-ffff-ffff-ffff-000000000100"]]
 [:db/add
  -2
  :id
  [:com.fulcrologic.rad.test-schema.address/id
   #uuid "ffffffff-ffff-ffff-ffff-000000000001"]]
]
2 things to note here: • nested arrays in entities will usually get turned into a triples structure, which is not what you want here. I think that the vector could just be included as the :id value (because :db/ident and :id are treated as special), but I'm playing it safe by adding the :id value after. • You have a quote character on the end of your attributes. This indicates that you're trying to update an attribute on an existing entity. But because you have negative numbers to represent the entities, then you're creating the entity. Which means that you're trying to update something that doesn't exist. Again, it will search for that thing, and not find it. Who knows what will happen at that point

Jakub Holý (HolyJak)06:04:51

Thank you very much! Correction: the last statement [:db/add [:id [:com.fulcrologic.rad.test-schema.address/id #uuid "ffffffff-ffff-ffff-ffff-000000000001"]] :com.fulcrologic.rad.test-schema.address/street' "A1 St"]] is not referring to the new entity -1 being created but it updates another, existing entity. So initially my db has an address entity and then this tx adds a new person entity and changes the street of the existing address. This statement was expected to update the :a/node-59555 :com.fulcrologic.rad.test-schema.address/street In my experience using lookup refs of [:id ...] (so "node-ref" is the correct term here?) as the subject works fine. Would you suggest that I do it differently? (I get a diff of added/changed/removed attribute+value pairs from #fulcro so translating that into a transactions with :db/add and :db/retract statements is simplest, and it is what its Datomic adapter is doing. With the map form, how do retractions work? Do I need to issue additional :db/retract or, if replacing an existing value with a new one, use the kwd' form? > You have a quote character on the end of your attributes. This indicates that you're trying to update an attribute on an existing entity. But because you have negative numbers to represent the entities, then you're creating the entity. Which means that you're trying to update something that doesn't exist. That is an artifact of my code. At the point where I create the tx statement, I do not know whether the attribute has an existing value or not so I play it safe and append ' , which seemed to work in my experiments. I was not aware that it is a bad thing to do for things that are actually new. I will stop being lazy and propagate the information that the target attribute is new to the code 🙂

quoll14:04:06

> In my experience using lookup refs of [:id ...] (so "node-ref" is the correct term here?) as the subject works fine It should work fine. > Correction: the last statement [:db/add [:id [:com.fulcrologic.rad.test-schema.address/id #uuid "ffffffff-ffff-ffff-ffff-000000000001"]] :com.fulcrologic.rad.test-schema.address/street' "A1 St"]] is not referring to the new entity -1 being created but it updates another, existing entity. OIC. I thought you were creating the address as well. Sorry. > With the map form, how do retractions work? Do I need to issue additional :db/retract or, if replacing an existing value with a new one, use the kwd' form? That's not committed yet. It's been asked for a bit lately, so I know it needs to happen. Meanwhile, people have been removing the triples themselves.

👍 1
Jakub Holý (HolyJak)17:04:17

Is it so that a tempid must be first used inside the {}-type transaction to actually be interpreted as a tempid? It does not work inside a single :db/add (unless I am making a mistake I can't see):

(->> @(d/transact (d/connect "asami:") {:tx-data [[:db/add -1 :inventory/replaced-by "dummy"]]})
       :db-after
       (d/q '[:find ?e ?a ?v :where [?e ?a ?v]]))
  ; => ([-1 :inventory/replaced-by "dummy"])
i.e. the node-id stays as -1 instead of being mapped to a real node id while the following works:
(->> @(d/transact (d/connect "asami:") {:tx-data [{:db/id -1 :i-exist true} [:db/add -1 :inventory/replaced-by "dummy"]]})
       :db-after
       (d/q '[:find ?e ?a ?v :where [?e ?a ?v]]))
=>
([:a/node-28249 :i-exist true]
 ..
 [:a/node-28249 :inventory/replaced-by "dummy"])
Is that what you were saying in your first answer? If this is true and is the expected / intended behavior then I will mention it explicitly at https://github.com/quoll/asami/wiki/4.-Transactions#temporary-ids

Jakub Holý (HolyJak)20:04:21

@U051N6TTC I wanted to create an issue at GH for ☝️ to make it easier for myself to track it but I see the project does not have issues enabled. I suppose that is intentional, so that you are not spammed by random people's desires. Let me know if I can help with this in any way!

quoll20:04:52

No, it's actually because it was a fork, and I got it detached. However, I want to get the threatgrid/asami issues ported over to quoll/asami. I meant to ask for that this morning. Thank you for the reminder. Meanwhile, maybe you could add your issue to threatgrid/asami, and it should make it when someone moves them for me (at least, I hope they will move them for me)

quoll20:04:18

OK. I sent the request

🙏 1
Jakub Holý (HolyJak)17:04:17

Is it so that a tempid must be first used inside the {}-type transaction to actually be interpreted as a tempid? It does not work inside a single :db/add (unless I am making a mistake I can't see):

(->> @(d/transact (d/connect "asami:") {:tx-data [[:db/add -1 :inventory/replaced-by "dummy"]]})
       :db-after
       (d/q '[:find ?e ?a ?v :where [?e ?a ?v]]))
  ; => ([-1 :inventory/replaced-by "dummy"])
i.e. the node-id stays as -1 instead of being mapped to a real node id while the following works:
(->> @(d/transact (d/connect "asami:") {:tx-data [{:db/id -1 :i-exist true} [:db/add -1 :inventory/replaced-by "dummy"]]})
       :db-after
       (d/q '[:find ?e ?a ?v :where [?e ?a ?v]]))
=>
([:a/node-28249 :i-exist true]
 ..
 [:a/node-28249 :inventory/replaced-by "dummy"])
Is that what you were saying in your first answer? If this is true and is the expected / intended behavior then I will mention it explicitly at https://github.com/quoll/asami/wiki/4.-Transactions#temporary-ids