With returns non correct :db-after

Hi, when with is executed for a DB that is gotten from the original DB by calling as-of function then the execution of with returns a map where the database available by key :db-after still points to the original DB. I mean when I use after db to get an updated entity I still see old data

The script to reproduce the issue:

(require '[datomic.api :as d])
(d/create-database "datomic:dev://localhost:4334/test?password=datomic")
(def conn (d/connect "datomic:dev://localhost:4334/test?password=datomic"))

(def user-schema [
                   {
                       :db/ident :User/name
                       :db/valueType :db.type/string
                       :db/cardinality :db.cardinality/one
                       :db/unique :db.unique/identity
                   }
                   {
                       :db/ident :User/value
                       :db/valueType :db.type/string
                       :db/cardinality :db.cardinality/one
                   }
                   ])
(d/transact conn user-schema)


(def user-name "User_name")
(def user-value "User_value")

(def user-data [
  {
    :db/id user-name
    :User/name user-name
    :User/value user-value
  }
])
(d/transact conn user-data)



(def user-updated-value "User_value_updated")
(def user-updated-data [
  {
    :User/name user-name
    :User/value user-updated-value
  }
])

(def db (d/db conn))
(def asOfDbByBasisT (d/as-of db (d/basis-t db)))


(def txResult (d/with asOfDbByBasisT user-updated-data))
(def snapshotDbAfter  (get txResult :db-after))
(def entity (d/entity snapshotDbAfter [:User/name user-name]))
(get entity :User/value)

“User_value” is returned instead of expected “User_value_updated”

Datomic Pro 1.0.6397

@jaret
Maybe it is related Q, what should be basis-t of DB gotten by the function as-of.

I see the basis-t of as-of DB is the same as DB used to get as-of db, is expected behavior?

(require '[datomic.api :as d])
(d/create-database "datomic:dev://localhost:4334/test-basis-t4?password=datomic")
(def conn (d/connect "datomic:dev://localhost:4334/test-basis-t4?password=datomic"))

(def user-schema [
                   {
                       :db/ident :User/name
                       :db/valueType :db.type/string
                       :db/cardinality :db.cardinality/one
                       :db/unique :db.unique/identity
                   }
                   {
                       :db/ident :User/value
                       :db/valueType :db.type/string
                       :db/cardinality :db.cardinality/one
                   }
                   ])
(d/transact conn user-schema)

(def user-name "User_name")
(def user-value "User_value")

(def user-data [
  {
    :db/id user-name
    :User/name user-name
    :User/value user-value
  }
])


(d/transact conn user-data)
(def db (d/db conn))
(def firstBasisT (d/basis-t db))


(def user-updated-value "User_value_updated")
(def user-updated-data [
  {
    :User/name user-name
    :User/value user-updated-value
  }
])
(d/transact conn user-updated-data)


(def db (d/db conn))
(def latestBasisT (d/basis-t db))

(def asOfDb (d/as-of db firstBasisT))
(def basisTFromAsOfDb (d/basis-t asOfDb))
(== latestBasisT basisTFromAsOfDb)

It is not clear to me why basisTFromAsOfDb is equal to latestBasisT
The doc says:
basis-t: Returns the t of the most recent transaction reachable via this db value.
But asOfDb can’t contain a transaction related to latestBasisT so why basis-t of asOfDb is latestBasisT

UPD. Maybe I got: if basis-t > than as-of-t of some db then it means it is possible to switch to the newer version of this db. Maybe would be good to point this moment somehow in the docs :slight_smile:

1 Like