fix: update_page properties now update in-place via upsertBlockProperty - #49
fix: update_page properties now update in-place via upsertBlockProperty#49nlsn wants to merge 1 commit into
Conversation
setPageProperties was appending properties as a new block body instead of updating the existing page-level property lines, making them invisible to Logseq's property system and rendering tag lists as Python repr strings. Switch update_page_with_blocks to use _update_page_properties, which calls upsertBlockProperty on the first block for each key. This updates properties in-place, preserves unspecified keys implicitly, and fixes tag serialization. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hi @ergut - before merging, I want to flag a potential secondary issue I haven't had time to investigate yet. The fix routes tag values through Could you hold off on merging until I've had a chance to test this? Thanks for your patience. |
|
Thanks for the PR, the careful repro in #48, and for flagging the tags wikilink concern yourself and asking to hold off. Good instinct: my review reached the same area and found some blocking issues, so here is the full picture.
A version I'd be glad to merge: gate on graph type. File mode uses Happy to help if you want to take this, otherwise I can pick it up and credit your repro. |
|
Thanks again for the careful repro in #48 and for flagging the wikilink concern. I went ahead and implemented the graph-type-aware version we discussed so this doesn't stall, and credited you as co-author on the commit. It gates the property write on graph type: DB graphs keep Opened it as #62. Happy to fold in any further thoughts you have on the tag semantics. |
update_page wrote page properties via setPageProperties for every graph
type. On file graphs that appends a serialized property block to the page
body instead of updating the `key:: value` lines in the first block, so
the properties never register with Logseq's property system.
Branch the property write path on graph type:
- DB graphs keep setPageProperties (page-entity level, the native
representation that registers with (page-property ...) queries).
- File graphs use upsertBlockProperty on the first block, the native
file-graph representation, updating values in place.
Append vs replace semantics are preserved in both modes:
- append upserts only the supplied keys (untouched keys survive),
- replace removes first-block keys absent from the new set before
upserting (new _replace_page_properties / _remove_block_property).
Plumb the db_mode flag from tools.py into the LogSeq client. Add tests
asserting the actual API call sequence for both modes on both graph types.
Builds on the repro and fix direction from #48 / #49.
Co-authored-by: Nelson Brown <813515+nlsn@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Closes #48. Supersedes #49 (credited @nlsn as co-author for the repro and direction). ## Problem `update_page` wrote page properties via `setPageProperties` for every graph type. On file graphs that appends a serialized property block to the page body instead of updating the `key:: value` lines in the first block, so the properties never register with Logseq's property system. The success message was misleading. This is the same area @nlsn surfaced in #48 / #49. #49 fixed it by switching to `upsertBlockProperty` unconditionally, but that regresses DB graphs: block-level properties don't register as page-level there (invisible to `(page-property ...)` queries and the page info panel). ## Fix Branch the property write path on graph type: * DB graphs keep `setPageProperties` (page-entity level, the native representation that registers with `(page-property ...)`). * File graphs use `upsertBlockProperty` on the first block, the native file-graph representation, updating values in place. This stays correct even after the upstream `setPageProperties` behavior in #51 is addressed. Append and replace semantics are preserved in both modes: * append upserts only the supplied keys, so untouched keys survive (merge semantics), * replace removes first-block keys absent from the new set before upserting, via new `_replace_page_properties` / `_remove_block_property`. The `db_mode` flag is plumbed from `tools.py` into the `LogSeq` client. ## Tests Rewrote the two property-update tests into four covering append and replace across both graph types, asserting the actual API call sequence (which method is called, on which block, with which keys) rather than only the returned dict. Full suite: 417 passing. Co-authored-by: Nelson Brown <813515+nlsn@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
Closes #48
Problem
update_pagecalled with apropertiesdict and nocontentwas routingthrough
_set_page_level_properties→logseq.Editor.setPageProperties.In practice,
setPagePropertiesappended a new block to the page body withproperties serialized as text, rather than updating the existing page-level
property lines in place. The appended block was invisible to Logseq's property
system and the success message was misleading.
Secondary bug: tag values were serialized as Python list repr (
['mcp-test'])instead of Logseq syntax (
[[mcp-test]]).Fix
In
src/mcp_logseq/logseq.py,update_page_with_blocks: replaced the_set_page_level_propertiescall (and the pre-fetch via_get_page_level_properties) with a single call to_update_page_properties.That method calls
logseq.Editor.upsertBlockPropertyonce per key on thefirst block (the page-properties pre-block), updating values in place and
implicitly preserving untouched keys.
The tags serialization bug is also resolved —
upsertBlockPropertyreceives aproper Python list and Logseq renders it correctly as
[[tag]]references.Tests Added
test_update_page_properties_only_updates_in_place— regression test;asserts no
setPageProperties/appendBlockInPagecall, and exactly NupsertBlockPropertycalls targeting the first blocktest_update_page_append_mode_merges_propertiesandtest_update_page_replace_mode_replaces_propertiesto match new API callsequence and result shape