fix(cli): upsert property --type on a property

that has property values makes a graph invalid as property values then
have the wrong types for their property pair. This isn't possible in the
UI because the property type change checks for existing data but the
db-worker-node level does not. This :logseq.property/type update bug was
also possible from plugin/API calls
This commit is contained in:
Gabriel Horner
2026-03-30 17:55:18 -04:00
parent 05fdb7d2ad
commit 8d30cd4a2d
2 changed files with 20 additions and 0 deletions

View File

@@ -221,6 +221,12 @@
{:type :notification
:payload {:message "This property can't change from multiple values to one value because it has existing data."
:type :warning}})))
(when (and (contains? changed-property-attrs :logseq.property/type)
(seq (d/datoms @conn :avet db-ident)))
(throw (ex-info "Disallowed type change with existing data"
{:type :notification
:payload {:message "This property's type can't be changed because it has existing data."
:type :error}})))
(when (seq tx-data)
(ldb/transact! conn tx-data {:outliner-op :update-property
:property-id (:db/id property)}))

View File

@@ -45,6 +45,20 @@
(:block/title (d/entity @conn :user.property/p1-2)))
"3rd property gets unique ident"))))
(deftest upsert-property-rejects-type-change-with-existing-data
(testing "Changing type is rejected when property has values"
(let [conn (db-test/create-conn-with-blocks
[{:page {:block/title "page1"}
:blocks [{:block/title "b1" :build/properties {:status "active"}}]}])]
(is (thrown-with-msg?
js/Error #"Disallowed type change with existing data"
(outliner-property/upsert-property! conn :user.property/status {:logseq.property/type :number} {})))))
(testing "Changing type is allowed when property has no values"
(let [conn (db-test/create-conn-with-blocks {:properties {:empty-prop {:logseq.property/type :default}}})]
(outliner-property/upsert-property! conn :user.property/empty-prop {:logseq.property/type :number} {})
(is (= :number (:logseq.property/type (d/entity @conn :user.property/empty-prop)))))))
(deftest convert-property-input-string
(testing "Convert property input string according to its schema type"
(let [test-uuid (random-uuid)]