Skip to content

fix(export): view and EDN exports keep child rows and import back whole - #13785

Closed
yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:fix/edn-export-combined
Closed

yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:fix/edn-export-combined

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

This PR combines #13681, #13744, which change the same files, into one branch on current master so they no longer conflict with each other. Each part is unchanged except where two of them touched the same lines.


#13681: fix(export): a view export keeps a row whose parent is also a row

Exporting the rows of a table or list view (export type :view-nodes) drops any row whose parent block is also a row. Example: a view lists "parent" and its child block "child"; the export contains only "parent", so "child" is lost on import.

Cause: build-blocks-export is called with :include-children? false for view exports, so it builds no parent-to-children map, but it still treats every block whose parent is among the exported blocks as a non-root. Such a block is then neither nested under its parent nor exported as a root.

Fix: with :include-children? false every given block is a root, so each row is exported once, flat, as view exports intend. Selected-node exports (:include-children? true) are unchanged.

Test: import-view-blocks-with-child-row in logseq.db.sqlite.export-test exports a parent and its child as view rows, checks both are in the export, imports it, validates the db and finds the child. On master it fails twice (the child is missing from the export and from the import); with the fix logseq.db.sqlite.export-test passes (45 tests, 191 assertions).

Found by mutation testing: changing :include-children? false to true in build-view-nodes-export made no existing test fail, and the changed version exported the child.


#13744: fix(export): EDN export of pages, blocks and selections imports back whole

Three ways an EDN export of a page, a block or a selection did not import back whole. Found by fuzzing export → import for every export type (:graph and :graph-human came back with no mismatch).

1. A selected block that another selected block references is exported twice

Selecting alpha and x where x has a node property source:: alpha (or a [[uuid]] ref to alpha) exports alpha twice on the same page: once as a selected node, once as a referenced block (build-uuid-block-export). The import creates a duplicate, or merges the two copies by uuid and the page's block order changes. build-page-export avoids this by dropping its own page; build-selected-nodes-export and build-view-nodes-export passed nothing.

Fix: build-uuid-block-export takes the nodes already in the export (:exported-nodes) and leaves them out. An exported node that is another node's property value keeps its uuid (:include-uuid-fn includes the property value entities), so the value still resolves.

2. A node property value on a nested block fails the import

A child block with source:: [[Alpha]], where page Alpha is not otherwise in the export: the export writes [:build/page {:block/title "Alpha"}] and relies on sqlite.build/add-new-pages-from-properties to create the page, but get-used-properties-from-options reads only each page's top-level :blocks, never :build/children, so the import throws No uuid for page '{:block/title "Alpha"}'. The same block at the top level imports fine.

Fix: get-used-properties-from-options also walks :build/children.

3. A ref inside a referenced block imports as a raw uuid

Exporting a block export [[middle]] where middle is middle [[Beta]]: middle is exported (shallow) with its title, but Beta is not, so the import shows middle [[<uuid>]].

Fix: build-content-ref-export follows refs in the titles of referenced blocks until no new ones turn up. The blocks it starts from include every value of a many node property (a set), not only single values.

Tests

In logseq.db.sqlite.export-test: import-selected-nodes-that-reference-each-other, import-selected-nodes-where-one-is-a-node-value-of-another, import-page-with-node-value-on-child-block, import-block-with-refs-two-levels-deep, import-block-with-node-value-whose-title-has-a-ref. Each fails or errors on master and passes with the fix; the other export tests pass.

The EDN export → import fuzzer (every export type, seeds 1 and 11) finds no mismatch with this PR. The text loops' remaining cases are logseq/db-test#1442.

…whole

- Selected nodes: a selected block that another selected block references was exported a second time; blocks already in the export are no longer added as referenced blocks.
- A node property value on a nested block pointing at a page outside the export failed the import (No uuid for page): sqlite.build now looks at nested blocks when it creates pages from property values.
- A referenced block is exported with its title, so the refs in that title are followed too; before, they imported as raw uuids.
…rty value; follow refs in many node values

With the selected block no longer exported twice, a selected block that is another selected block's node value lost the uuid the value points at (build-export: uuids are not defined). Such a node now keeps its uuid. Property values with many values (sets) were skipped when collecting the blocks whose title refs are followed.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined into #13869 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/edn-export-combined branch November 17, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant