Skip to content

Commit 6f0885b

Browse files
fix: importing a class via :parent that is then used
in :type property fails
1 parent bfffde8 commit 6f0885b

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

deps/graph-parser/src/logseq/graph_parser/exporter.cljs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,15 @@
8585
(swap! all-idents assoc (keyword class-name) (:db/ident m))
8686
(with-meta m {:new-class? true})))))
8787

88-
(defn- find-or-gen-class-uuid [page-names-to-uuids page-name db-ident]
89-
(or (get @page-names-to-uuids page-name)
88+
(defn- find-or-gen-class-uuid [page-names-to-uuids page-name db-ident & {:keys [temp-new-class?]}]
89+
(or (if temp-new-class?
90+
;; First lookup by possible parent b/c page-names-to-uuids erroneously has the child name
91+
;; and full name. To not guess at the parent name we would need to save all properties-from-classes
92+
(or (some #(when (string/ends-with? (key %) (str ns-util/parent-char page-name))
93+
(val %))
94+
@page-names-to-uuids)
95+
(get @page-names-to-uuids page-name))
96+
(get @page-names-to-uuids page-name))
9097
(let [new-uuid (common-uuid/gen-uuid :db-ident-block-uuid db-ident)]
9198
(swap! page-names-to-uuids assoc page-name new-uuid)
9299
new-uuid)))
@@ -128,7 +135,7 @@
128135
(let [class-m (find-or-create-class db new-class all-idents)
129136
class-m' (merge class-m
130137
{:block/uuid
131-
(find-or-gen-class-uuid page-names-to-uuids (common-util/page-name-sanity-lc new-class) (:db/ident class-m))})]
138+
(find-or-gen-class-uuid page-names-to-uuids (common-util/page-name-sanity-lc new-class) (:db/ident class-m) {:temp-new-class? true})})]
132139
(when (:new-class? (meta class-m)) (swap! classes-tx conj class-m'))
133140
(assert (:block/uuid class-m') "Class must have a :block/uuid")
134141
[:block/uuid (:block/uuid class-m')])

deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
(is (= 3 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Query]] @conn))))
195195

196196
;; Don't count pages like url.md that have properties but no content
197-
(is (= 9
197+
(is (= 10
198198
(count (->> (d/q '[:find [(pull ?b [:block/title :block/type]) ...]
199199
:where [?b :block/title] [_ :block/page ?b] (not [?b :logseq.property/built-in?])] @conn)
200200
(filter ldb/internal-page?))))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parent:: [[HumanConcept]]
2+
- this page triggers bug with a class created via :parent that is then used by :type
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type:: [[Priority]]

0 commit comments

Comments
 (0)