Welcome! Please see the About page for a little more info on how this works.

+3 votes
in On-Prem by
edited by

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)

1 Answer

0 votes

Hi Datomic peeps. Would you please consider a fix for this, or open-sourcing Datomic? Beginners are getting bitten by this using Datomic with reactive engines like Electric. I only use d/pull now and shy away from d/entity to avoid this bug. Datomic's tx listener is well-suited to reactive engines.

Welcome to the Datomic Knowledgebase, where you can make features requests, ask questions and receive answers from other members of the community.