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)))))