Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction append annotation fails on IPersistentMap #220

Open
kyleerhabor opened this issue Oct 17, 2021 · 1 comment
Open

Transaction append annotation fails on IPersistentMap #220

kyleerhabor opened this issue Oct 17, 2021 · 1 comment

Comments

@kyleerhabor
Copy link

It seems that a transaction using the + append annotation will fail when a map is supplied. For reference, I'm using Asami 2.2.1 and Clojure 1.10.3.855.

(def conn (d/connect "asami:local://demo"))
#'hue.server.core/conn

(d/transact conn [{:title "Demo"
                   :description "This is a demonstration of the append annotation failing on maps."
                   :contents [{:statement "Wow"}]}])
#object[java.util.concurrent.CompletableFuture 0x4e0964bb "java.util.concurrent.CompletableFuture@4e0964bb[Completed normally]"]

(d/entity (d/db conn) (asami.graph/new-node 1))
{:title "Demo",
 :description "This is a demonstration of the append annotation failing on maps.",
 :contents [{:statement "Wow"}]}
 
(d/transact conn [{:db/id (asami.graph/new-node 1)
                   :contents+ {:statement "What?"}}])
; Execution error (IllegalArgumentException) at asami.durable.encoder/eval22954$fn$G (encoder.clj:107).
; No implementation of method: :encapsulate-id of protocol: #'asami.durable.encoder/FlatFile found for class: clojure.lang.PersistentArrayMap

As FlatFile does not implement the encapsulate-id function for IPersistentMap, this error seems like expected behavior (or temporary).

IPersistentMap
(header [this len]
(general-header (type->code IPersistentMap) len))
(body [this]
;; If this is an identified object, then save it's location
(doseq [id-attr [:db/id :db/ident :id]]
(when-let [id (id-attr this)]
(vswap! *entity-offsets* assoc id @*current-offset*)))
(body (apply concat (seq this))))

If it's the case, how can I append a map to a vector? I could use the ' replacement annotation and set the vector as its previous items with the new one appended, but it seems inefficient and unintended.

@quoll
Copy link
Contributor

quoll commented Feb 23, 2022

IPersistentMap was the wrong thing to have here, and it's been fixed, but it's not the cause of this problem. In this case, there appears to be a missing code path for adding a map to the sequence (unless it's to be saved as a map object, but this isn't what the API is supposed to do here).

The latest version will actually save this map as a "value" in the list, which isn't consistent either. I'll see if I can track down where this is happening in the entity writer code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants