[dev-local] Internal error in expound when having Datomic DB as a var in a failing spec

In short the issue is that a datomic DB (d/db conn) looks like a regular map? to expound, which uses postwalk internally to traverse its values:

(require '[datomic.client.api :as d])
(walk/postwalk identity [(d/db conn)])

This results in the error java.lang.ClassCastException: class datomic.core.db.Datum cannot be cast to class java.lang.Number. Took a while to troubleshoot this :smiley: It’s now fixed by using Specter instead of postwalk.

The issue is reported here:

And a PR with a fix for this here:

To further elaborate, we were surprised to see that,

(map? (d/db conn))
;; => true

(keys (d/db conn))
;; => (:id :memidx :indexing :mid-index :index :history :basisT :nextEidx :indexBasisT :elements :keys :ids :index-root-id :index-rev :asOfT :sinceT :raw :filt :schema-level :birth-level :indexed-datoms :system-eids :t :as-of :since :history?)

And we have a feeling that this is tripping up postwalk and not allowing it to treat the DB as one unit, but attempting to break it down into parts, and reassemble it.

I.e., Expound is how we encountered this problem, but the problem is not with Expound itself. The same problem will appear wherever a DB appears in a data structure on which postwalk is applied.

This problem keeps occurring when where walk is involved, most recently here: Crash bug when printing, if a datomic db is present and the spec fails · Issue #209 · bhb/expound · GitHub

I’m guessing that this has to do with walk trying to take the DB apart and put it back together again, probably yielding nonsense.