Repository navigation
fix(db): deleting or converting a node no longer leaves what depended on it broken - #13882
yuxi-liu-wired wants to merge 18 commits into
Conversation
| property-value-blocks-tx (when (ldb/property? page) | ||
| (->> (:logseq.property/_created-from-property page) | ||
| (map (fn [value-block] | ||
| [:db/retractEntity (:db/id value-block)])))) |
There was a problem hiding this comment.
🔴 Property deletion strands nested content
When a text property value has children, build-page-retract-tx deletes the value but leaves its children. Their parent reference disappears, so nested content drops out of the outline.
Learn more
A text property's value is a block under the owning node. Unlike URL values, text values can have child blocks, as default-property-value-allows-children exercises. This transaction retracts the value block only. Retracting it also retracts inbound :block/parent datoms on its children, leaving those blocks on the page without a valid outline parent.
Example: Give the note value 2 liters on Buy milk a child called check expiration. Delete note: 2 liters disappears, but check expiration survives without a parent instead of staying in the outline.
Recommended fix: Choose an explicit policy for children of a deleted property's value. Reparent them to the owning block with valid order keys, or retract the full subtree if deletion is intended to remove nested content; cover the choice in an undo test.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (concat | ||
| [[:db/retract id :block/name] | ||
| [:db/add id :block/page (:db/id parent-page)]] | ||
| (children-page-tx (:db/id parent-page))))))))))) |
There was a problem hiding this comment.
🔴 Nested pages lose their own blocks
When a page containing a nested page is demoted, children-page-tx repoints the nested page's blocks to the outer parent. The nested page remains a page, but its blocks no longer belong to it.
Learn more
A block's :block/page identifies the page it belongs to. get-block-full-children-ids walks every :block/parent descendant, including those beneath nested pages. The predicate in children-page-tx skips each page entity but does not stop traversing its subtree. The new page-to-block call therefore rewrites blocks belonging to deeper pages.
Example: Page Parent contains page Outer, which contains page Inner and a block Inner note. Removing Outer's Page tag changes Inner note's :block/page from Inner to Parent, even though Inner is still a page.
Recommended fix: In children-page-tx, restrict rewrites to descendants whose current :block/page is the demoted page (or stop traversal at nested page boundaries). Test demotion with a nested page and its own child block.
Was this helpful? React with 👍 or 👎 to provide feedback.
| property-value-blocks-tx (when (ldb/property? page) | ||
| (->> (:logseq.property/_created-from-property page) | ||
| (map (fn [value-block] | ||
| [:db/retractEntity (:db/id value-block)])))) |
There was a problem hiding this comment.
🔴 Undo loses deleted property values
Deleting a used property now retracts its value blocks. build-inverse-delete-page restores only the property's page tree, so undo cannot restore values on other blocks.
Learn more
Deleting a property now retracts the value blocks attached to other nodes. The undo path build-inverse-delete-page reconstructs only the deleted property's own page tree using page-top-level-blocks, then restores the page's attributes. It does not reconstruct value blocks belonging to other pages or restore their property datoms. Undo therefore recreates the property definition without the values the delete just removed.
Example: Buy milk has note = 2 liters. Delete the note property and undo. The property returns, but Buy milk no longer has 2 liters.
Recommended fix: Extend the delete-page inverse to capture and restore every removed value block and owner property assignment, or use a validated raw inverse for this deletion. Add a deletion-and-undo test with a text value owned by a normal block.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (throw (ex-info "Disallowed type change with closed values" | ||
| {:type :notification | ||
| :payload {:message "This property's type can't be changed because it has closed values. Delete the closed values first." | ||
| :type :error}})))) |
|
c3248c3 to
c6fdfd4
Compare
… so it merges cleanly with logseq#13882 The tests this PR added at the end of pipeline_test.cljs sat at the same place as the ones logseq#13882 adds there, so the two PRs conflicted and the nightly merge left one of them out. The tests are unchanged; they now live in frontend.worker.pipeline-cli-refs-test, which carries the requires and the with-transact-pipeline helper they need, and pipeline_test.cljs is back to master's.
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
5800089 to
fc099b0
Compare
… so it merges cleanly with logseq#13882 The tests this PR added at the end of pipeline_test.cljs sat at the same place as the ones logseq#13882 adds there, so the two PRs conflicted and the nightly merge left one of them out. The tests are unchanged; they now live in frontend.worker.pipeline-cli-refs-test, which carries the requires and the with-transact-pipeline helper they need, and pipeline_test.cljs is back to master's.
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
fc099b0 to
51855bb
Compare
… so it merges cleanly with logseq#13882 The tests this PR added at the end of pipeline_test.cljs sat at the same place as the ones logseq#13882 adds there, so the two PRs conflicted and the nightly merge left one of them out. The tests are unchanged; they now live in frontend.worker.pipeline-cli-refs-test, which carries the requires and the with-transact-pipeline helper they need, and pipeline_test.cljs is back to master's.
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
51855bb to
0b90d6c
Compare
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
Changing a property's type after removing its values (for example Text to Node) went through even when the property still had closed values. The closed values stayed in the database but were no longer reachable from any UI, and a later "Validate graph" run treated every value of the property as not being a closed value and deleted them, so user data was silently lost. update-property only refused a type change when the property ident had datoms (values assigned to blocks). Closed values are blocks linked through :block/closed-value-property and leave no such datoms, so the check never saw them. A type change is now also refused when the property has closed values, with a notification asking the user to delete them first. This matches the existing refusal for a type change with existing data. Test: upsert-property-rejects-type-change-with-closed-values checks that the change throws and leaves the type and closed values untouched, and that it succeeds once the closed values are deleted. Fixes logseq/db-test#1069
…operty Deleting a text property left each value as an ordinary child block of the block that had it: with "Buy milk" holding note "2 liters", deleting "note" left a child block "2 liters" in the outline. Undoing the delete brought the property back but not the value on the block. build-page-retract-tx retracted each block's value datom and the property entity, but not the value blocks the datoms pointed to. Retracting the property entity also removed their :logseq.property/created-from-property mark, which is what hid them as values, so they showed as plain children. The value blocks of a property, found through :logseq.property/created-from-property, are now retracted with it. Test: delete-property-page-retracts-text-value-blocks deletes a text property that a block has set and checks the value block is gone and no child block is left behind. Fixes logseq/db-test#1304
Removing the Page tag from a page nested under another page turned it into a block under its parent, but the blocks inside it kept pointing at it as their page. A demoted block is not a page, so those blocks belonged to no page: they dropped out of the parent page's content and were missed by page-scoped queries, linked references and search. The page->block branch of toggle-page-and-block re-pointed only the demoted block's own :block/page to the parent page. The block->page branches already re-point descendants with children-page-tx, but this branch did not. The branch now re-points every descendant block's :block/page to the parent page too, using children-page-tx, which takes the target page. Test: convert-nested-page-to-block-repoints-descendants-to-parent-page-test removes the Page tag from a nested page with a child and a grandchild block and checks both belong to the parent page. Fixes logseq/db-test#1424
Refusing a property type change because the property has closed values showed a hard-coded English message, unlike the neighbouring property notifications, which carry an :i18n-key so the UI can show them in the user's language. The refusal now carries :property.validation/type-change-with-closed-values, with its English string in en.edn. Test: upsert-property-type-change-with-closed-values-notification-has-i18n-key checks the key on the thrown notification. Refs logseq/db-test#1069
Deleting a text property whose value block has children of its own (the value "2 liters" with a child "check expiration") left those children in the graph without a parent, and the delete failed the database's validation. The previous change deleted each value block of the property but not what was nested under it. The delete now removes each value block together with its whole subtree. Test: delete-property-page-retracts-children-of-text-value-blocks deletes such a property and checks that the child of the value block is gone. Refs logseq/db-test#1304
Deleting a property that blocks had set and pressing undo brought the property back but not its values: "Buy milk" with note "2 liters" lost the note, and the value blocks, with anything nested under them, stayed deleted. The inverse of a page delete for a property restored the property and the blocks on its page, but not the value blocks it took with it (they are children of the blocks that had the value, marked :logseq.property/created-from-property). The inverse now also re-inserts each value block with its subtree under the block it was a child of, with the property as its :created-from-property, which sets the block's property value again. Test: undo-delete-property-restores-text-values and undo-delete-property-restores-the-subtree-of-a-text-value delete a property, apply the inverse ops and check the value and the value block's child are back. Refs logseq/db-test#1304
…becomes a block Removing the Page tag from a page that holds another page (Outer, with Inner and Inner's block "Inner note") re-pointed the blocks of Inner to the parent page as well, so "Inner note" left its own page. children-page-tx walked the whole subtree of the converted node, through nested pages, and set every block's :block/page to the new page. The walk now stops at a nested page: only the blocks that belong to the converted node, not to a page inside it, are re-pointed. It is shared by the block->page conversions, which get the same boundary. Test: convert-page-to-block-keeps-nested-page-blocks-on-their-page-test demotes a page that holds a nested page with its own block and checks that the demoted page's block moves to the parent page while the nested page's block stays on the nested page. Refs logseq/db-test#1424
…-and-block stays under 100 lines
On master, deleting a number property that a block had set (num = 3) failed with "DB write failed with invalid data" and the property stayed. The value of a number property is a block marked as created from the property; deleting the property removed that mark and left the block behind without it, which the database rejects. The earlier change that deletes a property's value blocks with the property already fixes this, but no test covered a number property. Test: delete-number-property-page-with-a-value deletes such a property and checks that the delete succeeds, the property and its value block are gone, and the block that had the value stays. It fails on origin/master's page.cljs and passes here. Refs logseq/db-test#1304
…o it readable
A block that linked to a page ("b3 [[p2]]") kept the link in its text when the page went to the Recycle Bin. When the page was removed for good, by deleting it from the Recycle Bin or by the cleanup that runs after 30 days, the block still held the link to a page that no longer exists, a broken link that shows as a raw id.
The permanent removal deleted the page and its blocks and cleaned up references to deleted blocks, but nothing rewrote the references to a deleted page: the cleanup only handles blocks that are not pages.
Permanent deletion and the cleanup now turn the [[uuid]] of each removed page into the page's title, in the text of the blocks that linked to it, as deleting a page with a hard delete already does. Blocks that are removed together with the page are left alone.
Test: permanently-delete-recycled-page-keeps-referring-block-readable and gc-recycled-page-keeps-referring-block-readable recycle a page that a block links to, remove the page for good and check that the block reads "b3 p2".
Refs logseq/db-test#1349
… value block Setting a text property that already had a value to another value (text "one" to "beta") left the old value block in the graph, owned by nothing: it kept its text, showed up in search and added to the size of the database. The text value of a property is a block of its own, marked as created from the property. set-block-property! made a new value block and pointed the property at it, but nothing deleted the one it replaced. Removing a property already deletes such a value block when no other node holds it; replacing the value did not. set-block-property! now deletes the value blocks it stops using, with their children, when no other node holds them. A value block that another node still holds, a closed value, a page, or the property's default value is kept. Test: set-block-property-deletes-the-replaced-text-value-block sets text "one" to "beta" and checks that no block with the old text remains, and that a value block held by a second block is kept. Refs logseq/db-test#1304
CI's typos check reads every changed file, and this branch changes en.edn.
… blocks Removing a text property that had several values (many = x, y) from a block left the value blocks "x" and "y" in the graph, owned by nothing: they kept their text, showed up in search and added to the size of the database. remove-block-property! deletes the value blocks no other node holds, but only for a single value or a vector of them. The values of a many-valued property are a set, so none were deleted. The rule for which value blocks to delete moves to one function, logseq.outliner.value-blocks/orphaned-value-blocks-tx, used when a property is removed from blocks and when a property is set to another value. It takes the entities of any collection of values, deletes the value blocks of the property that no other node holds, with their children, and keeps a closed value, a page and the property's default value. Test: remove-block-property-deletes-many-text-value-blocks removes a many-valued text property and checks that no value block is left, and that a value block a second block still holds is kept. Refs logseq/db-test#1304
…cks it held A block with a number property (num = 3) on a page that was deleted and then removed for good, by deleting it from the Recycle Bin or by the cleanup that runs after 30 days, left the number's value block in the graph, owned by nothing: it showed up in search and added to the size of the database. A number value is a block that belongs to its property, not to the block that has it, so removing the page and its blocks did not remove it. The permanent removal and the cleanup now also delete the property value blocks that the removed nodes held, with their children, unless a node that stays holds them. It uses logseq.outliner.value-blocks/orphaned-value-blocks-tx, the same rule as when a property is removed from a block or set to another value. Test: permanently-delete-recycled-page-deletes-the-number-values-it-held and gc-recycled-page-deletes-the-number-values-it-held remove such a page for good; gc-keeps-a-number-value-another-block-holds checks that a value a block on another page holds is kept. Refs logseq/db-test#1304
… longer fails Setting a number property to 0 or to a negative number (num = 0, num = -3) through set-block-property! or batch-set-property! failed with "Expected number or lookup ref for entity id, got 0", so the value was not saved. Other numbers worked. Typing "0" in the number input was not affected, the input sends text. An integer given for a number property may be the entity id of one of the property's closed values (the closed-value picker passes ids), so convert-ref-property-value looked every integer up with d/entity to see whether it is such a value block. d/entity throws for 0 and for negative numbers. An integer is now read as an entity id only when it is positive; 0 and negative numbers are always values. Entity ids are positive, so the callers that pass them (the closed-value picker, the plugin API with entityId, :entity-id? true) are unchanged, and :entity-id? false still forces a literal. Test: set-block-property-stores-zero-and-negative-numbers sets 0 (also over an existing value), a negative number, "0" typed as text, and the many-valued [0 2] through set-block-property! and batch-set-property! without :entity-id?.
… its property history With "Enable property history" on a number property, setting it from 4 to 5 recorded that it had been 4. Since the value blocks that nothing holds any more are deleted, the old value block 4 was deleted as soon as the property was set to 5, and deleting a value block also deletes the history records that point at it, so the history lost the 4. Removing the property from the block lost the removed value the same way. Permanently removing a page (Recycle Bin or the cleanup after 30 days) had the same rule and would also have dropped the history of a block that stays. orphaned-value-blocks-tx now keeps a value block that a property history record points at, unless that record belongs to a node being deleted or to a property being deleted (the records go with them). Callers that delete nodes pass them as deleted-ids; the helper that finds the value blocks held by deleted nodes moves from recycle to the value-blocks namespace. Test: changing-a-number-value-keeps-the-value-its-history-records sets and removes a history property; gc-keeps-a-number-value-the-history-of-a-block-that-stays-records and permanently-delete-recycled-page-deletes-the-number-value-and-history-it-held cover the permanent removal of a page. Refs logseq/db-test#1304
A block with a number property (num = 7) that was deleted left the number's value block in the graph, owned by nothing: it kept its value, showed up in search and added to the size of the database. A number value is a block that belongs to its property, not to the block that has it, so deleting the block did not delete it. Setting the property to another value, removing it and removing a page for good already deleted such a value block. delete-blocks now also deletes the property value blocks that the deleted blocks held, with their children, unless a block that stays holds them or a history record of a block that stays points at them. It uses logseq.outliner.value-blocks/deleted-nodes-value-blocks-tx, the same rule as the permanent removal of a page. Test: delete-blocks-deletes-the-number-values-it-held deletes blocks that hold their own value and a shared value (the shared one is kept while a block holds it); delete-blocks-deletes-the-number-value-and-history-of-the-block checks a history property. Refs logseq/db-test#1304
75fe14e to
0d5bb0c
Compare
… so it merges cleanly with logseq#13882 The tests this PR added at the end of pipeline_test.cljs sat at the same place as the ones logseq#13882 adds there, so the two PRs conflicted and the nightly merge left one of them out. The tests are unchanged; they now live in frontend.worker.pipeline-cli-refs-test, which carries the requires and the with-transact-pipeline helper they need, and pipeline_test.cljs is back to master's.
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
…what depended on it broken (squashed: its commits conflicted one by one with the stack)
…, so recycle.cljs merges cleanly with logseq#13786 The cleanup this PR added to with-delete-cleanup-tx in recycle.cljs sat on the same lines as the one logseq#13786 adds there, so the two PRs conflicted and the nightly merge left one of them out. with-delete-cleanup-tx, its neighbours and the end of the require list are back to master's; the page-title and value-block cleanup moves to with-permanent-delete-cleanup-tx, which wraps it for the two permanent deletes (delete from the recycle bin, and the 30 day gc). Same cleanup, so nothing changes for the user.
0d5bb0c to
20e3bf2
Compare
… so it merges cleanly with logseq#13882 The tests this PR added at the end of pipeline_test.cljs sat at the same place as the ones logseq#13882 adds there, so the two PRs conflicted and the nightly merge left one of them out. The tests are unchanged; they now live in frontend.worker.pipeline-cli-refs-test, which carries the requires and the with-transact-pipeline helper they need, and pipeline_test.cljs is back to master's.
…lock Setting a Text property on blocks that already had a value through batch-set-property! (the add-property value picker, multi-block edits, the plugin API) left the old value block behind, and so did removing one of several values of a many-valued Text property. These hidden blocks keep their text, show up in search and grow the graph, owned by no node. Cause: batch-set-property! replaces the property datom and never deletes the value blocks it replaces, and batch-delete-property-value! retracts only the datom of the removed value. Change: both delete the text value blocks of the property that no other node holds once these blocks stop holding them (with their children, through outliner-core/delete-blocks, as batch-remove-property! does). Choices, pages and the property's default value are kept, and a scalar added to a many-valued property keeps the other values. This is the same cleanup set-block-property! and batch-remove-property! get in logseq#13882, for the two paths that change does not touch. Test: logseq.outliner.property-value-blocks-review-test/replaced-text-value-blocks-are-deleted counts the value blocks of the property and their holders after replacing a value on one and on two blocks, after replacing a choice, and after removing one of two values.
… so it merges cleanly with logseq#13882 The tests this PR added at the end of pipeline_test.cljs sat at the same place as the ones logseq#13882 adds there, so the two PRs conflicted and the nightly merge left one of them out. The tests are unchanged; they now live in frontend.worker.pipeline-cli-refs-test, which carries the requires and the with-transact-pipeline helper they need, and pipeline_test.cljs is back to master's.
Fixes logseq/db-test#1069, fixes logseq/db-test#1304, fixes logseq/db-test#1424.
Several bugs in one theme: a node is removed, replaced or converted and something that depended on it is left broken. Each fix is its own commit; the review follow-ups are separate commits on top. The links to a page removed for good are related to logseq/db-test#1349 (refs to a recycled page) but do not decide it: only the permanent removal is covered here.
What the user sees
rasterandvector) can have its type changed, say to Node, once no block uses it any more. The closed values stay in the database but appear in no UI surface. A later "Validate graph" run then deletes every value of the property, so data is silently lost.num = 3) failed with "DB write failed with invalid data" and the property stayed. It now succeeds and the property and its value are gone.onetobeta) left the old value block in the graph, owned by nothing. It kept its text, showed up in search and grew the database. It is now deleted.many = x, y) from a block left the value blocksxandyin the graph, owned by nothing, with the same effects.num = 3) on a page that was deleted and then removed from the Recycle Bin (or cleaned up after 30 days) left the number's value block in the graph, owned by nothing.b3 [[p2]]) kept the link when the page was deleted and later removed from the Recycle Bin (or cleaned up after 30 days), and then showed a broken link to a page that no longer exists. It now readsb3 p2.Cause
update-propertyindeps/outliner/src/logseq/outliner/property.cljsrefuses a type change only when(d/datoms @conn :avet db-ident)is non-empty, i.e. when blocks carry values for the property. Closed values are blocks linked through:block/closed-value-propertyand leave no such datoms, so a property whose values were all removed passed the check with its closed values still attached.build-page-retract-txindeps/outliner/src/logseq/outliner/page.cljsretracts each block's value datom and the property entity, but not the value blocks the datoms point to. Retracting the property entity also removes their:logseq.property/created-from-propertymark, which is what hid them as values, so they show as plain children. The inverse of a page delete indeps/outliner/src/logseq/outliner/op/construct.cljcrestored the property and the blocks on its page, but not these value blocks.set-block-property!made a new value block and pointed the property at it, but nothing deleted the one it replaced; removing a property already deletes such a block when no other node holds it (batch-remove-property!), replacing the value did not. Nothing inset-block-property!orcreate-property-text-block!keeps the old block on purpose, and a value block is shared only when a caller sets the same block on several nodes, which is handled below.remove-block-property!deletes the value blocks no other node holds, butbatch-remove-property!only looked at a single value or a vector of them. The values of a many-valued property are a set, so none were deleted.permanently-delete!,gc!) deleted the page and its blocks and cleaned up references to deleted blocks, but nothing rewrote references to a deleted page: the cleanup indelete_blocks.cljsonly handles blocks that are not pages. This is the same rewrite thatdelete!does when it moves a page to the Recycle Bin and that hard-deleting a class or property does, which did not cover pages removed later.toggle-page-and-blockinsrc/main/frontend/worker/pipeline.cljsre-points only the demoted block's own:block/pageto the parent page. The block->page branches already re-point descendants withchildren-page-tx, but that walk went through nested pages as well.Change
:block/_closed-value-propertyis non-empty). The thrown notification says the type can't be changed because the property has closed values and asks the user to delete them first, and carries:property.validation/type-change-with-closed-values(English string inen.edn). This follows the existing "Disallowed type change with existing data" refusal and does not delete anything on the user's behalf.build-page-retract-txalso deletes the value blocks of a deleted property, found through:logseq.property/created-from-property, each with its whole subtree, in the same transaction as the property.build-inverse-delete-pagere-inserts those value blocks with their subtrees under the block they were children of, with the property as:created-from-property, which sets the owner's property value again.logseq.outliner.value-blocks/orphaned-value-blocks-tx, decides which value blocks go: the value blocks of a property among the ones a node lets go of that no other node holds, with their children. A value block another node still holds, a closed value, a page and the property's default value are kept.set-block-property!uses it for the values it replaces,batch-remove-property!for the values it removes (now including every value of a many-valued property), andwith-delete-cleanup-txinrecycle.cljsfor the values held by the nodes thatpermanently-delete!andgc!remove.with-delete-cleanup-txindeps/outliner/src/logseq/outliner/recycle.cljsalso turns the[[uuid]]of each page it removes into the page's title, in the stored title of the blocks that linked to it (not of blocks removed with the page). Bothpermanently-delete!(and the:recycle-delete-permanentlyop) andgc!use it. Moving a page to the Recycle Bin is unchanged, so this does not depend on the choice for fix(ui): Page title show null #1349.children-page-txtakes the page to point at and stops at nested pages, so only the blocks that belong to the converted node are re-pointed. The page->block branch uses it to re-point every such descendant to the parent page.Tests
upsert-property-rejects-type-change-with-closed-valuesindeps/outliner/test/logseq/outliner/property_test.cljs: a property with two closed values and no assigned values (no datoms under its ident) rejects a change to:node, keeps its type and closed values, and accepts the change after the closed values are deleted.upsert-property-type-change-with-closed-values-notification-has-i18n-keychecks the i18n key of the notification.delete-property-page-retracts-text-value-blocksanddelete-property-page-retracts-children-of-text-value-blocksindeps/outliner/test/logseq/outliner/page_test.cljs: deleting a text property that a block has set removes the value block and its child, and leaves no child block behind.undo-delete-property-restores-text-valuesandundo-delete-property-restores-the-subtree-of-a-text-valueindeps/outliner/test/logseq/outliner/move_property_value_undo_test.cljs: after deletingnote("2 liters" on "Buy milk") and applying the inverse ops, "Buy milk" hasnote= "2 liters" again, and a child of the value block is back. The test leaves out the inverse's final:save-blockof the property page, becauseoutliner-core/save-blockmerges onto the page entity, which nbb's datascript entity does not support.delete-number-property-page-with-a-valueindeps/outliner/test/logseq/outliner/page_test.cljsdeletes a number property that a block has set and checks the delete succeeds, the property and its value block are gone and the block stays. It fails on origin/master'spage.cljs(the delete throws "DB write failed with invalid data") and passes here.set-block-property-deletes-the-replaced-text-value-blockindeps/outliner/test/logseq/outliner/property_test.cljssets textonetobetaand checks that no block with the old text remains, and that a value block a second block still holds is kept. It fails without the fix (the old block stays) and passes with it.remove-block-property-deletes-many-text-value-blocksindeps/outliner/test/logseq/outliner/property_test.cljsremoves a many-valued text property and checks that no value block is left, and that a value block a second block still holds is kept. It fails without the fix (the value blocks stay) and passes with it.permanently-delete-recycled-page-deletes-the-number-values-it-heldandgc-recycled-page-deletes-the-number-values-it-heldindeps/outliner/test/logseq/outliner/recycle_test.cljsremove a recycled page whose block hasnum = 3and check the number's value block is gone;gc-keeps-a-number-value-another-block-holdschecks that a value a block on another page holds is kept. The first two fail without the fix.permanently-delete-recycled-page-keeps-referring-block-readableandgc-recycled-page-keeps-referring-block-readableindeps/outliner/test/logseq/outliner/recycle_test.cljsrecycle a page that blockb3links to, remove it for good and check thatb3readsb3 p2, notb3 [[<uuid>]].convert-nested-page-to-block-repoints-descendants-to-parent-page-testandconvert-page-to-block-keeps-nested-page-blocks-on-their-page-testinsrc/test/frontend/worker/pipeline_test.cljs: removing the Page tag from a nested page with a child and a grandchild block leaves both on the parent page, and a block of a page nested inside the demoted page stays on that page.Each new test fails without its fix and passes with it. The
deps/outlinersuite and the main unit-test suite pass.Fixes logseq/db-test#1073: setting a text property to a new value leaves the old value block behind (the "Setting a text property to a new value" fix above). Pinned by
set-block-property-deletes-the-replaced-text-value-blockin deps/outlinerproperty_test.cljs.Added: number values, found by a node-ops fuzzer
Three more commits, found by a fuzzer that runs random outliner operations (page/block conversion, recycle and GC, property values with history) and checks after each that the graph validates and no entity is left pointing at a deleted one.
What the user sees
num = 0ornum = -3through the API, the CLI or any op that passes the number itself failed with "Expected number or lookup ref for entity id, got 0" and the value was not saved. Other numbers worked. Typing0in the number input was not affected, because the input sends text.Cause
convert-ref-property-value(deps/outliner/src/logseq/outliner/property.cljs) treats an integer given for a number property as a possible entity id of a closed value (the closed-value picker passes ids) and checks it with(d/entity @conn v), which throws for 0 and for negative numbers. The caller paths:set-block-property!always,batch-set-property!when:entity-id?is not given. The text typed into the number input is a string and goes throughparse-double, so it never reached the check.orphaned-value-blocks-tx(deps/outliner/src/logseq/outliner/value_blocks.cljs) decides a value block is garbage when no node holds it. A property history record also holds it (:logseq.property.history/ref-value), anddelete-blocks/update-refs-historyretracts every record pointing at a retracted entity.delete-blocks(deps/outliner/src/logseq/outliner/core.cljs) retracts the block and its children, but a number value is a block that belongs to its property and is not among them.Change
:entity-id? falsestill forces a literal.orphaned-value-blocks-txkeeps a value block that a history record points at, unless the record's block or property is being deleted (then the record goes with it). The recycle cleanup passes the nodes it deletes. The function that finds the value blocks held by deleted nodes moves fromrecycleto thevalue-blocksnamespace.delete-blocksalso deletes the value blocks the deleted blocks held (with their children), through the same rule, unless a block that stays holds them or a history record of a block that stays points at them.Tests
set-block-property-stores-zero-and-negative-numbers(property_test):set-block-property!with 0 (also over an existing value) and -3,batch-set-property!without:entity-id?, the text "0", and the many-valued[0 2].changing-a-number-value-keeps-the-value-its-history-records(property_test),gc-keeps-a-number-value-the-history-of-a-block-that-stays-recordsandpermanently-delete-recycled-page-deletes-the-number-value-and-history-it-held(recycle_test).delete-blocks-deletes-the-number-values-it-heldanddelete-blocks-deletes-the-number-value-and-history-of-the-block(core_test).Each fails without its commit's source change and passes with it;
pnpm testindeps/outliner(178 tests) and the whole main-bundle suite pass.Not changed
extendsis a plain page that the cleanup deletes) belongs to fix(db): sync checksum and local graphs, page and tag names, orphaned pages, tag deletion, recycled values, and unreachable code #13786; the fuzzer still reports it on this branch alone and no longer on fix(db): sync checksum and local graphs, page and tag names, orphaned pages, tag deletion, recycled values, and unreachable code #13786 merged with this branch. The two PRs conflict textually inrecycle.cljs(three additive hunks, keep both).