Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/datascript/db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,15 @@
:else
(let [first-a (first a)
first-b (first b)
diff (cmp first-a first-b)]
diff (try
(cmp first-a first-b)
(catch #?(:clj ClassCastException :cljs js/Error) _
:incomparable))]
(cond
(== diff 0) (recur only-a only-b (conj both first-a) (next a) (next b))
(< diff 0) (recur (conj only-a first-a) only-b both (next a) b)
(> diff 0) (recur only-a (conj only-b first-b) both a (next b)))))))
(= diff :incomparable) (recur (conj only-a first-a) (conj only-b first-b) both (next a) (next b))
(== diff 0) (recur only-a only-b (conj both first-a) (next a) (next b))
(< diff 0) (recur (conj only-a first-a) only-b both (next a) b)
(> diff 0) (recur only-a (conj only-b first-b) both a (next b)))))))

;; ----------------------------------------------------------------------------

Expand Down
9 changes: 9 additions & 0 deletions test/datascript/test/issues.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@
filtered (ds/filter base (constantly true))]
(t/is (= (with-out-str (clojure.pprint/pprint base))
(with-out-str (clojure.pprint/pprint filtered)))))))

(deftest ^{:doc "Can't diff databases with different types of the same attribute"}
issue-369
(let [db1 (-> (ds/empty-db)
(ds/db-with [[:db/add 1 :attr :aa]]))
db2 (-> (ds/empty-db)
(ds/db-with [[:db/add 1 :attr "aa"]]))]
(t/is (= [[(ds/datom 1 :attr :aa)] [(ds/datom 1 :attr "aa")] nil]
(clojure.data/diff db1 db2)))))