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

+3 votes
in Client API by

Environment

  • com.datomic/client-cloud 1.0.119
  • com.datomic/dev-local 1.0.242

History

Reproducible in both dev-local and Cloud client implementations.

(require '[datomic.client.api :as d])

(def client (d/client {:server-type :dev-local
                       :system      "test"
                       :storage-dir :mem}))

(d/create-database client {:db-name "bug-example"})

(def conn (d/connect client {:db-name "bug-example"}))

(d/transact conn {:tx-data [{:db/ident       :name
                             :db/valueType   :db.type/string
                             :db/cardinality :db.cardinality/one}]})

(def tx-report
  (d/transact conn {:tx-data [{:db/id "a"
                               :name  "kenny"}]}))

(def db-id (get-in tx-report [:tempids "a"]))

(d/pull (d/db conn)
  [:db/id]
  db-id)
=> {:db/id 83562883711050, :name "kenny"}

Expectation

Issuing d/pull with a selection of [:db/id] will only pull the :db/id attribute.

Actual

Issuing d/pull with a selection of [:db/id] will only pull all attributes on the given entity.

Evidence

See repro in History.

Impact

This bit me when doing some debugging in the REPL. I was trying to just get the db/id of a "top-level" entity, and it pulled the whole thing. This top-level entity is massive and resulted in me needing to restart my REPL. The ability to pull the entirety of an entity is a bit frightening, especially if such a thing were to happen (on purpose or accident) in production. The use of a [*] pull pattern is almost always avoided for this reason. Tracking down a bug like this could be quite tricky since it looks so innocent by appearance.

1 Answer

0 votes
by

This bug boxes me in a corner ... I don't know the "type" of the entity whose :db/id I'm trying to pull, so I can't add an addtional attribute to work around the problem. And just using [*] has the big liability noted in the report above.

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