From c536d5a13206971006767584d7881180fb126963 Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Thu, 20 Jun 2024 14:19:46 +0200 Subject: [PATCH] Fix :db.fn/call returning entity without :db/id --- src/datascript/db.cljc | 2 +- test/datascript/test/transact.cljc | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/datascript/db.cljc b/src/datascript/db.cljc index d23d1b52..5a86aad2 100644 --- a/src/datascript/db.cljc +++ b/src/datascript/db.cljc @@ -1766,7 +1766,7 @@ (util/cond+ (= op :db.fn/call) (let [[_ f & args] entity] - (recur report (concat (apply f db args) entities))) + (recur report (concat (assoc-auto-tempids db (apply f db args)) entities))) (and (keyword? op) (not (builtin-fn? op))) diff --git a/test/datascript/test/transact.cljc b/test/datascript/test/transact.cljc index cf0a3927..347e2ad2 100644 --- a/test/datascript/test/transact.cljc +++ b/test/datascript/test/transact.cljc @@ -474,3 +474,10 @@ (is (empty? (->> (d/datoms db :eavt) (map (fn [[_ a v]] [a v])) (remove #(d/entity db %))))))) + +(deftest test-db-fn-returning-entity-without-db-id-issue-474 + (let [conn (d/create-conn {}) + _ (d/transact! conn [[:db.fn/call (fn [db] + [{:foo "bar"}])]]) + db @conn] + (is (= #{[1 :foo "bar"]} (tdc/all-datoms db)))))