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

Unique identity entities are not unified correctly in transactions #363

Closed
claj opened this issue Aug 20, 2020 · 2 comments
Closed

Unique identity entities are not unified correctly in transactions #363

claj opened this issue Aug 20, 2020 · 2 comments

Comments

@claj
Copy link
Contributor

claj commented Aug 20, 2020

Upgrading from datascript 0.18.13 to datascript 1.0.0 gives me a regression as follows:

(require '[datascript.core :as d])

(def simple-schema {:user/id #:db{:unique :db.unique/identity},
                    :message/inbox #:db{:valueType :db.type/ref}})

(def conn (d/create-conn simple-schema))

(d/transact conn [{:db/id -1
                   :user/id #uuid "5bd85317-a414-4a9c-b3c8-b00827c0f219"}])

(d/transact conn [[:db/add -1 :user/id #uuid "5bd85317-a414-4a9c-b3c8-b00827c0f219"]
                  [:db/add -2 :message/text "hello"]
                  [:db/add -2 :message/inbox -1]])

The last row throws an exception in datascript 1.0.0:

Tempids used only as value in transaction: (-1)
{:error :transact/syntax, :tempids {1 -1}}
db.cljc: 1281  datascript.db$check_value_tempids/invokeStatic
db.cljc: 1272  datascript.db$check_value_tempids/invoke
db.cljc: 1300  datascript.db$transact_tx_data/invokeStatic
db.cljc: 1284  datascript.db$transact_tx_data/invoke
core.cljc:  230  datascript.core$with/invokeStatic
core.cljc:  223  datascript.core$with/invoke
core.cljc:  437  datascript.core$_transact_BANG_$fn__6939/invoke
Atom.java:   37  clojure.lang.Atom/swap
core.clj: 2352  clojure.core/swap!
core.clj: 2345  clojure.core/swap!
core.cljc:  436  datascript.core$_transact_BANG_/invokeStatic
core.cljc:  433  datascript.core$_transact_BANG_/invoke
core.cljc:  531  datascript.core$transact_BANG_/invokeStatic
core.cljc:  443  datascript.core$transact_BANG_/invoke
core.cljc:  637  datascript.core$transact/invokeStatic
core.cljc:  630  datascript.core$transact/invoke
core.cljc:  634  datascript.core$transact/invokeStatic
core.cljc:  630  datascript.core$transact/invoke
REPL:  787  traktor.testa-ds/eval72332

expected

The expected behaviour is that the :db/add statement [:db/add -1 :user/id #uuid "5bd85317-a414-4a9c-b3c8-b00827c0f219"] should unify -1 to the already created database entity id (which in this case is 1) and that this should be resolved in value position in the statement the [:db/add -2 :message/inbox -1], which is how datascript 0.18.13 works.

@tonsky
Copy link
Owner

tonsky commented Aug 20, 2020

Yes, seems like a bug. Sorry, will take a look and fix!

@tonsky tonsky closed this as completed in e022a09 Aug 28, 2020
@tonsky
Copy link
Owner

tonsky commented Aug 28, 2020

Fixed in 1.0.1. Thanks for reporting!

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