Browse Source

fix: db import of namespaced page created invalid class

Encountered this with docs graph. Part of LOG-3176
Gabriel Horner 1 year ago
parent
commit
60cd9b00da

+ 2 - 0
deps/db/src/logseq/db/frontend/db_ident.cljs

@@ -39,6 +39,8 @@
               (string/replace-first #"^\d+" "")
               (string/replace " " "-")
               (string/replace "#" "")
+              ;; '/' cannot be in name - https://clojure.org/reference/reader
+              (string/replace "/" "-")
               (string/trim))]
     (assert (seq n) "name is not empty")
     (keyword user-namespace n)))

+ 9 - 0
deps/db/test/logseq/db/frontend/db_ident_test.cljs

@@ -0,0 +1,9 @@
+(ns logseq.db.frontend.db-ident-test
+  (:require [cljs.test :refer [deftest is]]
+            [logseq.db.frontend.db-ident :as db-ident]))
+
+(deftest create-db-ident-from-name
+  (is (= "Whiteboard-Object"
+         ;; Example from docs graph
+         (name (db-ident/create-db-ident-from-name "user.class" "Whiteboard/Object")))
+      "ident names must not have '/' because it is a special symbol for the reader"))

+ 8 - 0
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -348,6 +348,10 @@
           conn (d/create-conn db-schema/schema-for-db-based-graph)
           _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
           _ (import-files-to-db files conn {:tag-classes ["movie"]})]
+
+    (is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
+        "Created graph has no validation errors")
+
     (let [block (find-block-by-content @conn #"Inception")
           tag-page (find-page-by-name @conn "Movie")
           another-tag-page (find-page-by-name @conn "p0")]
@@ -372,6 +376,10 @@
           conn (d/create-conn db-schema/schema-for-db-based-graph)
           _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
           _ (import-files-to-db files conn {:property-classes ["type"]})]
+
+    (is (empty? (map :entity (:errors (db-validate/validate-db! @conn))))
+        "Created graph has no validation errors")
+
     (let [block (find-block-by-content @conn #"The Creator")
           tag-page (find-page-by-name @conn "Movie")]
       (is (= (:block/content block) "The Creator")