Transaction / Indexing bug

Aperta
#376 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
clojure
Ambito
databases

Direzione di ricerca

Inizia eseguendo la riproduzione mostrata nell’issue con d/db-with, d/touch e l’indice :aevt. Traccia come viene elaborata durante la transazione una map contenente :foo/relations e riferimenti inversi. Il lavoro è completo quando db-with-foo-backwards conserva foo3 e i relativi datom di relazione, e il touch delle entità correlate non genera più un’asserzione su entity?.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In a transaction where a map has refs and reverse-ref attributes, the ref attributes are thrown away.

This works:


(require '[datascript.core :as d])

(def db
  (d/empty-db
    {:foo/id        {:db/unique :db.unique/identity}
     :foo/relations {:db/valueType   :db.type/ref
                     :db/cardinality :db.cardinality/many}}))

(def db-with-foo
  (d/db-with
    db
    [{:foo/id        "foo1"
      :foo/relations [{:foo/id "foo2"}
                      {:foo/id "foo3"}]}]))

(comment
 (d/touch (d/entity db-with-foo [:foo/id "foo3"]))
; works!
; => {:foo/id "foo3", :db/id 3}
)

This fails for :foo/relations [{:foo/id "foo3"}] but works for the reverse :foo/_relations:


(def db-with-foo-backwards
  (d/db-with
    db
    [{:foo/id         "foo2"
      :foo/_relations [{:foo/id "foo1" :foo/relations [{:foo/id "foo3"}]}]}]))

(comment
 (d/touch (d/entity db-with-foo-backwards [:foo/id "foo3"]))
; errors!
; => #object[Error Error: Assert failed: (entity? e)] 

; relation between "foo1" and "foo2" exists
(d/touch (d/entity db-with-foo-backwards [:foo/id "foo1"])) 
 ; => {:foo/id "foo1", :foo/relations #{#:db{:id 1}}, :db/id 2}
)

Looking at the indexes of either DB we see that the relations and datoms are missing in db-with-foo-backwards:

(comment
 (:aevt db-with-foo)
; =>
;#{#datascript/Datom[1 :foo/id "foo1" 536870913 true]
;  #datascript/Datom[2 :foo/id "foo2" 536870913 true]
;  #datascript/Datom[3 :foo/id "foo3" 536870913 true] ; <-- foo3 exists!
;  #datascript/Datom[1 :foo/relations 2 536870913 true]
;  #datascript/Datom[1 :foo/relations 3 536870913 true]}
)
(comment
  (:aevt db-with-foo-backwards)
; =>
;#{#datascript/Datom[1 :foo/id "foo2" 536870913 true]
;  #datascript/Datom[2 :foo/id "foo1" 536870913 true] ; <-- foo3 and relations missing!
;  #datascript/Datom[2 :foo/relations 1 536870913 true]}
)
Lingua principale
Clojure
Stelle
5.8k
Fork
318
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tonsky/datascript

Tutte le issue di tonsky/datascript

Issue simili

Altre issue su Clojure

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.