From 87aed88c8e6a30027c289c2aeccd8987efc98b7c Mon Sep 17 00:00:00 2001 From: jonasseglare <5850088+jonasseglare@users.noreply.github.com> Date: Tue, 24 Sep 2024 21:57:28 +0200 Subject: [PATCH] Fix attribute refs bug when transacting tuple value (#696) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue #695 Co-authored-by: Jonas Östlund --- src/datahike/db/transaction.cljc | 2 +- .../test/attribute_refs/transact_test.cljc | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/datahike/db/transaction.cljc b/src/datahike/db/transaction.cljc index ddad6271b..3839b8b24 100644 --- a/src/datahike/db/transaction.cljc +++ b/src/datahike/db/transaction.cljc @@ -591,7 +591,7 @@ (defn check-tuple [db op-vec] (let [[_ _ a v] op-vec - attr-schema (-> db dbi/-schema a)] + attr-schema (-> db dbi/-schema (get a))] (cond (:db/tupleType attr-schema) (cond (> (count v) 8) (raise "Cannot store more than 8 values for homogeneous tuple: " op-vec diff --git a/test/datahike/test/attribute_refs/transact_test.cljc b/test/datahike/test/attribute_refs/transact_test.cljc index 0b19f3250..bb04aa36a 100644 --- a/test/datahike/test/attribute_refs/transact_test.cljc +++ b/test/datahike/test/attribute_refs/transact_test.cljc @@ -189,3 +189,17 @@ (is (= (:age e) 32)) (is (:had-birthday e))) (d/release conn))) + +(deftest test-tuples + (let [conn (setup-new-connection)] + (d/transact conn [#:db{:ident :mapping/attributes, + :valueType :db.type/tuple, + :tupleTypes + [:db.type/keyword :db.type/keyword :db.type/keyword], + :cardinality :db.cardinality/many}]) + (d/transact conn [{:mapping/attributes [[:mapping :mapped-id :remote-id]]}]) + (is (= #{[[:mapping :mapped-id :remote-id]]} + (d/q '[:find ?v + :where [?e :mapping/attributes ?v]] + @conn))) + (d/release conn)))