Expected: entity object equality semantics to consider their database value in determining equality, such that entities derived from differing database values are not equal
Observed: entities derived from inconsistent database values are considered equal.
(def edward 694891374557546)
(def db2 (:db-after (d/with test/datomic-db [[:db/add edward :google/display-name "a"]])))
(= (d/entity test/datomic-db edward) (d/entity db2 edward)) ; true
Why we care: when using Datomic entity API with a reactive dataflow engine, the reactive engine uses =
to detect dirty expressions to schedule reevaluation, and here, two very different entity values are considered equal causing the reactive engine to incorrectly cache the expression without reevaluating (i.e. reuse a buffered prior instance of the entity that is inconsistent with the latest db).
also see https://github.com/tonsky/datascript/issues/433 – Datascript had the same bug.
Impl note: false negatives are not an issue (i.e. in the case of two equal database values that are not identical references, returning a false negative here may be acceptable, resulting in imperfect caching but no visibly broken behavior in user apps)