fix(cli): don't apply upsert block tags/properties to referenced pages - #13129
Open
dalxds wants to merge 1 commit into
Open
fix(cli): don't apply upsert block tags/properties to referenced pages#13129dalxds wants to merge 1 commit into
dalxds wants to merge 1 commit into
Conversation
`upsert block` in create mode applied `--update-tags` and `--update-properties` to the ids returned by `Add.execute_add_block`. Those ids come from `resolve_created_ids`, which reads the insert transaction's `tx-data` and so includes pages the transaction created or touched to satisfy `[[page]]` references in the block content — not just the blocks the caller asked to create. Creating a block whose content links a page therefore stamped the block's tags and properties onto that page as well, overwriting any shared property (for example `source`) it already had. Both entities were written in a single `batch-set-property` transaction, so the page silently gained the tag. Target the action's own block uuids instead, falling back to id resolution only when the action carries none. This is the pattern `execute_task_create` in the same module already uses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
upsert blockin create mode applies--update-tagsand--update-propertiesto pages referenced from the block's content, not just to the block being created.Creating a block that links a page silently tags that page and overwrites properties on it. In a scripted graph build this is data loss: every page linked from block content picked up the block's tags, and shared property names (
source, in my case) were overwritten on pages that already had a correct value.Reproduction
Actual — the referenced page carries the block's tag and property:
Expected:
Targetis unchanged; only the new block carries them.The referenced page does not need to pre-exist — a page auto-created by the reference is affected the same way. Confirming both entities are written together:
One
batch-set-propertytransaction, both entities — so the page id reachedbatch-set-property!as a target.Root cause
execute_create_block(cli/lib/upsert.ml) applies the resolved update plan to the ids returned byAdd.execute_add_block:Those ids come from
Add.resolve_created_ids, which prefers uuids collected from the insert transaction'stx-data:Since
2d1f17ee2b("fix: add CLI block page refs"), the insert payload carries:block/refsentity maps for[[page]]references, so the insert transaction creates or touches those pages and their uuids land intx-data. The update plan is then applied to the caller's block and to every page it references.The scope is limited to this call site.
execute_task_createin the same module already does the right thing, and the asset path only returns the ids without applying an update plan.Fix
Target the action's own block uuids, falling back to id resolution only when the action carries none — the pattern
execute_task_createalready uses:Tests
Added
block-upsert-update-tags-not-applied-to-referenced-page-jsontocli-e2e/spec/non_sync_cases.edn. It creates a block linking a page with both--update-tagsand--update-properties, then assertslist node --tagsreturns exactly one node — the block — with no second (page) entry. The case fails before this change and passes after.Also recorded the bug in
docs/cli/ocaml-cli-bugs-and-fixes.md, matching the existing entry format.Not fixed here
upsert blockstill reports referenced pages as created blocks:That comes from the same
resolve_created_idstx-data behaviour and feeds the bug above. It looked like a separate, wider-blast-radius change (the ids are returned to callers and asserted in existing specs), so I left it out to keep this PR focused on the data-corruption path. Happy to follow up if you'd like it addressed.Notes for reviewers
dune fmt-checked locally — it needs CI. It's structurally identical to the workingexecute_task_createcode a few hundred lines above, and lines stay within the 80-columnocamlformatmargin.cli/lib/add.mlis byte-identical tomaster) reproduces it.