Skip to content

fix(import): EDN and file-graph import - #13886

Open
yuxi-liu-wired wants to merge 33 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-1381
Open

yuxi-liu-wired wants to merge 33 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-1381

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Combines the PRs of this theme, to keep the number of open PRs down; the commits are unchanged. CI's unit suite passes on the combined branch.

fix(import): EDN export and import keep pages, history, search and the target block (was #13886)

Fixes logseq/db-test#1381, fixes logseq/db-test#958, fixes logseq/db-test#1004, fixes logseq/db-test#1420, fixes logseq/db-test#1385.

This PR fixes five EDN import/export bugs. Each fix is its own commit with its own test.

What the user sees

Cause

  • When editing in the latest web version of logseq, the letter c cannot be entered normally. #1381: Ctrl+K clears the editor state, and get-current-page-id only read the page of the last edited block from it. Despite its docstring it never looked at the route, so it returned nil.
  • Push && Pull 失败 #958: The import matches an exported class or property to the one in the target graph by ident and uses the target's uuid, but the exported page of that class or property kept the exported uuid. No page has that uuid in the target graph, so the import treated it as an existing page and built a stub with only a uuid and timestamps, which fails validation. Only pages matched by title had their uuid remapped.
  • Conflict Merge deleted entire file #1004: <current-import-block returns nil after warning "No block found" (the command palette clears the editor state), and import-edn-data-from-form treated nil as "no block needed" and went on to build the import of a block export without a block.
  • feat: add vimeo video embed block command #1420: The graph import retracts every entity of the target graph and then adds the exported datoms, which reuse entity ids. ldb/transact! then ran its cleanup for deleted blocks over that transaction, which saw the imported history records referring to ids that the same transaction retracts, and retracted them. The existing import tests transact with d/transact! into an empty graph, so they did not catch it.
  • Graph and Page Graph #1385: The import transaction is marked as imported data and the worker's search listener skips every transaction with that mark. That is right for creating a graph from an EDN file, but it also applied to an import into an existing graph, which has a search index that needs the new nodes.

Change

  • When editing in the latest web version of logseq, the letter c cannot be entered normally. #1381: get-current-page-id looks at the page in the route first and returns [:block/uuid <page-uuid>], which pull and export-edn accept, then falls back to the last edited block as before (src/main/frontend/util/page.cljs).
  • Push && Pull 失败 #958: check-for-existing-entities records the uuid remap of existing classes and properties, as it already did for pages matched by title, so the exported page and references to it use the existing node and its blocks are added to it (deps/db/src/logseq/db/sqlite/export.cljs).
  • Conflict Merge deleted entire file #1004: import-edn-data-from-form closes without importing when it is importing a block export and <current-import-block returned nil. Other kinds of export are still imported without a current block (src/main/frontend/handler/db_based/import.cljs).
  • feat: add vimeo video embed block command #1420: ldb/transact! skips the deleted blocks cleanup for transactions marked as imported data by logseq.db.sqlite.export, since the import replaces the data and has nothing to clean up (deps/db/src/logseq/db.cljs).
  • Graph and Page Graph #1385: The search listener skips the sync only for the EDN import that creates a graph (:import-db?) and syncs for an EDN import into an existing graph. Other imports are unchanged (src/main/frontend/worker/db_listener.cljs).

Tests

  • When editing in the latest web version of logseq, the letter c cannot be entered normally. #1381: get-current-page-id-test in src/test/frontend/util/page_test.cljs covers the route page with the editor state cleared, the route preferred over a stale editor state, and the two editor fallbacks. Without the fix: 2 failures. With the fix: passes, and the whole unit suite passed.
  • Push && Pull 失败 #958: import-class-and-property-pages-when-they-exist-with-different-uuids in deps/db/test/logseq/db/sqlite/export_test.cljs imports the pages of a class and a property into a graph where both exist with other uuids. Without the fix: 6 failures (validation error, blocks missing from the existing pages, stub pages with the exported uuids). With the fix: passes.
  • feat: add vimeo video embed block command #1420: graph-datom-import-through-ldb-transact-keeps-property-history in the same file imports a graph with property history into a graph that already has content, transacting with ldb/transact! like the worker's :thread-api/import-edn. Without the fix: 1 failure (0 history records after import, 1 expected). With the fix: passes. The whole deps/db suite passes with all the deps/db fixes (202 tests, 772 assertions, 0 failures).
  • Conflict Merge deleted entire file #1004: import-edn-block-without-current-block-does-not-import-test and import-edn-page-without-current-block-imports-test in src/test/frontend/handler/db_based/import_test.cljs submit the Import EDN form with no block being edited. Without the fix: 2 failures (an import is applied, two notifications are shown). With the fix: passes.
  • Graph and Page Graph #1385: db-listener-syncs-search-for-edn-import-into-existing-graph-test in src/test/frontend/worker/db_listener_test.cljs checks the search sync for an EDN import into an existing graph and for one that creates a graph. Without the fix: 1 failure. With the fix: passes. The older db-listener-skips-search-sync-for-imported-data-test only checks that nothing is synced right away and the listener syncs asynchronously, so the new test waits for it.
  • The main test bundle was built once without the Conflict Merge deleted entire file #1004 and Graph and Page Graph #1385 fixes and once with them, and the whole unit suite (pnpm cljs:run-test) passed except frontend.persist-db-test/electron-import-and-download-open-real-worker-in-fresh-graphs (a "Worker request timeout" while another build and suite were running on the machine); that namespace passes when run alone (46 tests, 208 assertions, 0 failures).

fix(import): file-graph import keeps tables in quotes and Zotero PDF assets (was #13891)

Fixes logseq/db-test#1048, fixes logseq/db-test#1408, fixes logseq/db-test#1469, fixes logseq/db-test#1009.

This PR fixes bugs in the file graph to DB graph importer (deps/graph-parser), most found by a fuzzer that imports generated markdown graphs and checks that nothing is lost, duplicated or invalid. Each fix is its own commit with its own test.

What the user sees

  • Case inside properties is always being converted to lower-case #1048: A table inside a quote (#+BEGIN_QUOTE with text and a markdown table, or > | a | b |) is dropped by the import.
  • Page embed does not show the correct capitalization. #1408: A Zotero linked PDF that {{zotero-linked-file}} gives as an absolute path does not become an asset when the graph has a Zotero linked attachment base directory, and the imported PDF can't be opened (the viewer looks in <base>/<absolute path>).
  • Search fails for words that are present after about 44 characters in a bullet #1469: A Zotero PDF that is not on disk loses its asset, its annotations and the references to them. In the reported graph the import failed on a dangling block reference and left an empty graph.
  • Feat: add google login #1009: With "Import all tags", a tag and a property of the same name (#scheduled and scheduled:: true) can end up as one invalid entity that is both a class and a property.
  • A page file that starts with template:: x aborts the whole import ("No property schema found for nil").
  • A block with SCHEDULED: or DEADLINE: and then properties keeps the property lines in its title, so the text is both in the title and in the properties. The same happens for properties after a table.
  • A property that is a checkbox or a number in one file and text in a later file aborts the import of the later file ("Expected number or lookup ref for entity id, got nil").
  • A block ref as a property value (rating:: ((uuid))) stays as literal ((uuid)) text.
  • A title:: property on any block other than the first renames the whole page, and a journal with one is not created.
  • With "Import all tags", a namespaced tag #ns/a creates a second page a when ns/a/b already created ns/a as a namespace page.

Cause and change

  • Case inside properties is always being converted to lower-case #1048 (498b4804a2): ast->text, which writes the content of quotes into the block title, had no branch for a Table node. It writes a Table node as a markdown table now.
  • Page embed does not show the correct capitalization. #1408 (390394e147): resolve-asset-data joined the base directory with the path of the macro even when it is absolute. It uses an absolute path (including a Windows drive path) as is. (a0e98a3b7e) The PDF viewer's get-zotero-local-pdf-path (src/main/frontend/extensions/pdf/assets.cljs) did the same with the imported zotero-link://<absolute path>, so opening the PDF or an annotation looked in <base>/<absolute path>. It returns an absolute path as it is and joins only a relative one.
  • Search fails for words that are present after about 44 characters in a bullet #1469 (69708710ac): <ensure-asset-data! creates the asset of a PDF that can't be stat'ed only for external? PDFs, and a Zotero PDF, which only points at the Zotero item, wasn't one. It is treated as external now.
  • Feat: add google login #1009 (41fe859006, 43060e7a62): The tag and the property of a name get distinct entities (the class and the property page), but the properties saved for the property page included :logseq.property.class/extends from the tag of the same name, which a property can't have; they are dropped now. A second case: when an earlier file created the page of the name, the file that makes it a class also converted that existing page into the property; an existing page that becomes a class in the file now stays the class and the property gets its own entity.
  • Page template:: (1005fb27ee): the property was mapped to a DB property that doesn't exist. template:: and template-including-parent:: on a page are ignored and reported in the ignored properties.
  • Properties after a planning line (aff441a9f3): properties are only removed from a title when they directly follow the first line, and the planning lines were removed after that. They are removed first.
  • Properties after a table (74f35c411e): remove-properties also skips the table lines of a block that starts with a table.
  • Boolean/number to text (c943486491): the importer retracted the old values of the property as entities, and a checkbox or number value is not an entity (it retracted the entity nil). A value that is an entity is retracted as an entity, any other value as a value of the property.
  • Block ref in a property value (c9a17a08e2, bb6a00eb40): the text of a property value block was not converted from ((uuid)) to [[uuid]] as block titles are. The first commit also added the refs, which failed the import when the target block comes from a later file; the second leaves the refs to the finalizing of the import, which builds them from the title.
  • title:: (f4ea81df98): the page name came from the first properties node anywhere in the file; only the page properties, which come before the first block, count now.
  • Namespaced tag (7743ad7b94): the importer only looked for an existing class by the name of the tag. When there is a page with that namespaced name, the tag is converted into the class on that page.

Tests

  • deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs: import-table-in-block, import-zotero-linked-file-with-absolute-path, import-zotero-pdf-annotations-when-the-pdf-is-missing, import-tag-and-property-of-same-name-when-the-page-has-a-file-convert-all-tags, import-tag-and-property-of-same-name-when-an-earlier-file-created-the-page-convert-all-tags, import-page-template-property, import-properties-after-planning-line-are-not-in-title, import-property-changing-from-boolean-to-text, import-page-property-changing-from-boolean-to-text, import-block-ref-in-property-value, import-title-property-of-a-block-does-not-rename-the-page, import-namespaced-tag-of-a-namespace-page-convert-all-tags. Each fails on master and passes with its fix.
  • deps/graph-parser/test/logseq/graph_parser/property_test.cljs: test-remove-properties-after-table.
  • src/test/frontend/extensions/pdf/assets_test.cljs: get-zotero-local-pdf-path-test (main bundle; fails without the fix, whole unit suite passes).
  • The deps/graph-parser suite passes with pnpm test -e integration (125 tests, 1437 assertions, 0 failures). The ^:integration test export-docs-graph-with-convert-all-tags times out ("Import timed out after 30000ms") in this environment on master as well, so it could not be run to completion.

Fuzzer, master vs this branch

40 generated graphs (seeds 1 to 40), number of failures per property; FUZZ_REPORTED=1 adds the inputs of the aborting bugs. Full lists in ~/tmp/fuzz-*.out.

property master branch
block-missing, lost-text/block-token, lost-text/quote-first-table-cell, lost-text/table-header (tables in quotes) 15 each 0
block-parent 5 0
prop-text-left-in-title/after-planning-line 33 0
prop-text-left-in-title/no-planning-line 25 13
valid, tag-and-property, prop-key-lost/scheduled 1 each 0
lost-text/asset-png-label, lost-text/asset-pdf-label (#1081) 34, 25 34, 25
prop-key-lost/* 1 16
page-missing/prop-*-ref (not minimized) 9 9
page-missing/ref, ref-lost 1, 1 1, 1
with FUZZ_REPORTED=1: block-ref-syntax-left/property-value 25 1
with FUZZ_REPORTED=1: import-error 5 (seeds 10, 19, 28, 37, 40) 4 (10, 19, 37, 40)

The 13 no-planning-line and the prop-key-lost failures are the same quote blocks: > | a | b | followed by key:: v. A line without > after a quote line is a lazy continuation of the quote, so the properties stay in the quote text and are not parsed. They were hidden behind the missing quote tables on master.

Not included

fix(import): file-graph import keeps pages of one name apart, whatever the file order (was #13911)

Fixes logseq/db-test#1378.

These commits came from #13911, which is now the storage PR only. The import collision fuzzer imports each graph in three file orders and checks it. On this branch it passes all of seeds 1-40, with every property at 0.

In convert-tag-to-class, this PR's lookup of an existing namespace page in the db (find-existing-namespace-page-uuid) and #13911's lookup in the import's name index are combined. A tag #work/b becomes the class of an earlier page work/b, whether that page is already in the db or only in the current file.

A page named like a namespace page's last part is merged into the namespace page

What the user sees. In a file graph with the pages projects/b and b, if projects/b appears in an earlier file than b, the import has no root page b. Every later [[b]] links to projects/b, and the blocks of pages/b.md are appended to projects/b. With the other file order the import makes two pages, so the result depends only on file names. No warning is shown and the graph validates.

Cause. The db stores the namespace page projects/b with the name b. The import's own name index keys namespace pages by their full name, but three db lookups by name found the namespace page by the bare name b: the page uuid in extract, the existing-page fallback in lookup-imported-page-uuid and the page entity in page-name-string->map.

Change. When importing, gp-block/get-page skips pages with a namespace parent, and the three lookups use it.

Tests. logseq.graph-parser.exporter-page-merge-test imports pages/a___b.md before pages/b.md, and a [[projects/b]] ref before a [[b]] ref, and checks that there are two pages, each with its own blocks and refs. It also imports b, projects/sub/b and sub/b and checks that sub/b sits under a root page sub, not under projects/sub (the same lookup one level up). All three fail on master.

A journal file and a page file for the same date make an undeletable page

What the user sees. A file graph with journals/2023_06_21.md and pages/Jun 21st, 2023.md (such page files exist after a change of :journal/page-title-format, or when a date page was created as a normal page) imports a journal page tagged both #Journal and #Page. It fails validation ("should not have other built-in page tags when tagged with #Page"), and every later write to it, including deleting it, fails with "DB write failed with invalid data".

Cause. The journal file creates the page with #Journal first. For the page file, build-existing-page runs update-page-tags on the incoming page map, which adds #Page when the incoming tags have no page class. It does not look at the tags the existing page already has.

Change. build-existing-page leaves #Page out when the existing page already has another page class (#Journal, #Whiteboard, a tag or a property).

Tests. logseq.graph-parser.exporter-page-merge-test imports a journal file and a page file for the same date, with and without page tags, and checks that the page is a journal without #Page, that the graph validates and that the page can be deleted. Both fail on master.

The same page collisions through other entry points: file order, tags, aliases

The importer collision fuzzer (mutation/lib/exporter_fuzz_test.cljs, each graph imported in three file orders) still found these on the two fixes above.

What the user sees.

  • A pages/ file named like a journal file of the import, imported first (for example pages/Dec 31st, 2025.md next to journals/2025_12_31.md, in a graph whose config.edn has no :journal/page-title-format), becomes a plain page. The journal file then merges into it. The result is a page tagged #Journal and #Page without a journal day, whose journal blocks are on no page and which cannot be deleted.
  • With convert-all-tags? on, #projects/x makes a class x that extends projects. A later pages/x.md or [[x]] lands on that class, so there is no root page x.
  • With convert-all-tags? on, [[work/b]] and then #work/b make a page b and a class b, both under work.
  • With convert-all-tags? on, a tag naming a journal date (#[[Dec 31st, 2025]]) turns the journal into a class, and the graph does not validate.
  • A page with alias:: [[Jan 5th, 2026]] imported before journals/2026_01_05.md makes the whole import fail with "Nothing found for entity id [:block/uuid ...]".

Cause.

  • Without a title format, the page file is not recognized as a journal, while the import indexes journal files by their canonical title.
  • A namespaced class has no :block/parent, only an extends, so the namespace-child check in gp-block/get-page missed it.
  • The import's name index also keyed the class's page map, saved without its parent, by its bare name. It read :block/tags with contains?, which is false on the vector a new class carries.
  • The class built for #work/b took the tag's new uuid instead of the uuid of the page work/b already in the index.
  • convert-tag? did not exclude journal days.
  • An alias was written as a [:block/uuid ...] lookup ref to a journal page that does not exist yet.

Change.

  • A page whose name is a journal file of the import becomes that journal (uuid, journal day, #Journal) before it is built.
  • gp-block/get-page also skips classes that extend a class other than Root.
  • The name index skips the bare name of a uuid that is also saved under its full name, and reads tags as a collection.
  • A namespaced tag converted to a class takes the uuid of the page of that full name when one exists, so that page becomes the class.
  • A journal day is never converted to a class.
  • Aliases are {:block/uuid ...} maps, as block refs already are.

Tests. exporter-page-merge-test covers a page file before its journal file (through export-file-graph with a config.edn without a title format), a date tag, a page file and a journal file in one graph, and an alias of a journal imported before the journal. exporter-convert-tags-test covers #projects/x before pages/x.md and [[x]], [[work/b]] before #work/b, and a journal date as a tag. Each fails before its fix.

Links and tags that depend on the file order

What the user sees.

  • With convert-all-tags? on, #x or tags:: x in a file imported after #work/x points at the class work/x. Imported in another order, it points at a class x, and the page x is a #Tag in one order and a #Page in the other.
  • A pages/ file named like a journal day (pages/Jan 5th, 2026.md) with no journal file for that day is a plain page when it comes first. A later [[Jan 5th, 2026]] or alias of that name adds #Journal to it, giving a page tagged #Journal and #Page without a journal day that cannot be deleted. With the other order, the import makes a valid journal.

Cause.

  • find-existing-class looked up a tag without a namespace by name only, and the namespaced class work/x is stored with the name x.
  • The importer reads pages/ files with skip-journal?, so their titles never become journals, while refs and aliases to the same name do.

Change.

  • find-existing-class skips namespaced classes for a tag without a namespace.
  • The page of a pages/ file whose title is a journal title is built as that journal: in the graph's title format, or matching a journal file of the import. It gets the journal uuid, day and canonical name, and #Journal instead of #Page. This replaces the earlier rule, which only covered names of journal files of the import.

Tests. exporter-convert-tags-test imports #work/x before #x. exporter-page-merge-test imports pages/Jan 5th, 2026.md before a page that aliases it. Both fail before the fix.

Shared aliases. When two pages declare the same alias, or an alias declares aliases itself, the source graph has a conflict. The importer keeps the first declaration in import order and reports the others in the import report (:alias/duplicate-owner, :alias/source-is-alias, :alias/alias-owns-aliases). The app imports files sorted by path, so the first page in path order keeps a shared alias.

Fuzzers. The importer collision fuzzer passes all of seeds 1-20 and 21-40, with every property at 0. Before this PR, seeds 1-20 had 14 failing. The fuzzer now leaves reported alias conflicts out of its comparison between orders. The storage fuzzer passes all 30 seeds.

A tag that starts another tag in another case (edcb8c8)

Found by the importer collision fuzzer on the fork's nightly (seed 4024), minimised to one line; master has it too. - x #A/B #a imported as x [[a]]/B [[a]]: the block lost its link to A/B and showed a broken /B. Tags are replaced ignoring case and as plain text, in the order sort-refs gives, which compares titles case-sensitively and put a before A/B, so #a replaced the #A of #A/B. #Foo-bar #foo had the same problem. replace-tags-with-id-refs now replaces the longest title first (nested page titles still first), so a tag that is the start of another one is replaced after it. Tests: logseq.db.frontend.content-tag-prefix-test (2 of 3 fail without the change, all pass with it; the existing content-test passes).

Rebase onto master 29fd2ed: master's fail-fast import test

Master's export-file-graph-fails-fast-with-relative-path-and-reason (deps/graph-parser exporter_test.cljs) used two inputs that this PR fixes as files that must fail the import: pages/T.md with a page template:: property ("No property schema found for nil") and pages/B.md with vegetarian:: yes after pages/A.md set it to false. With this PR both import, so the test saw no failure. The test pins the fail-fast error path (the file's path and the reason in the error), so both page files now use the query-sort-by input of the test's journal case, which still fails; the helper's assertions on path, reason and later files are unchanged.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Devin Review

Comment thread src/main/frontend/util/page.cljs Outdated
Comment on lines +25 to +26
(or (some->> (get-route-page-uuid) (vector :block/uuid))
(get-in (first (state/get-editor-args)) [:block :block/page :db/id])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Page export targets a block instead

On a block UUID route, get-current-page-id selects the block instead of its parent page. Page export then exports the wrong entity.

Learn more

A page route can identify a block, not just a page. redirect-to-page! routes a block UUID to :page when it has no named heading route, and the page component can render an entity with :block/page. The route-first lookup returns that block's UUID directly, while export-page-data passes the result to page export as a page ID. The prior editor-state lookup used the block's parent page ID.

Example: Navigate to an ordinary block using its UUID, then run “Export page EDN data.” The export selects the block entity instead of the page containing that block.

Recommended fix: Resolve the route UUID to its entity and use its :block/page when present, falling back to the entity itself only when it is a page. Preserve the editor-state fallback when the route cannot be resolved.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +178 to +179
(and (= :batch-import-edn (:outliner-op tx-meta))
(not (:import-db? tx-meta))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Direct worker imports retain the search gap

The worker import endpoint sets the imported-data flag without :batch-import-edn. Its imports still skip search sync; confirm whether this endpoint serves existing graphs.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

1. A route that opens a block as a page (util/page.cljs). Fixed in 472a73b. get-current-page-id is now <get-current-page-id. It asks the worker for the entity of the route's uuid and uses its :block/page when it has one (a block that was opened as a page), and the entity itself otherwise (a page). It still falls back to the last edited block when the route has no page, or when the route's entity is not found. The two callers (export-page-data, show-page-data) now wait for the result. The renderer has no synchronous way to look up the entity, which is why the function is now async. get-current-page-id-test covers a page route, a block route, a route whose entity is not found, and the editor fallbacks; without the change it fails on the block route and on the others that now go through the worker (4 failures), and the whole unit suite passes with it.

2. :thread-api/import-edn still skips search sync. This is not limited to new graphs. The endpoint takes any open repo, retracts every entity in it and adds the exported datoms, so it replaces the whole graph. The repo only calls it from tests; the CLI's graph import is the user of it, and whether that graph is new is decided by the CLI, which this repo does not show. So after that endpoint the search index of the replaced graph is stale, new graph or not. I left it alone in this PR: #1385 is about "Import EDN data" into an existing graph, which is the :batch-import-edn path that now syncs search, and syncing a full replacement needs its own decision (sync every datom, or clear and rebuild the index).

@yuxi-liu-wired yuxi-liu-wired changed the title fix(import): EDN export and import keep pages, history, search and the target block fix(import): EDN and file-graph import Oct 28, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 29, 2026
…ace, so it merges cleanly with logseq#13886

The test this PR added to import_test.cljs sat at the same place as the ones logseq#13886 adds there, so the two PRs conflicted and the nightly merge left one of them out. The test is unchanged; it now lives in frontend.handler.db-based.import-edn-dialog-test, which carries the requires and the sample EDN it needs, and import_test.cljs is back to master's.
yuxi-liu-wired pushed a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
…mmits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
…ace, so it merges cleanly with logseq#13886

The test this PR added to import_test.cljs sat at the same place as the ones logseq#13886 adds there, so the two PRs conflicted and the nightly merge left one of them out. The test is unchanged; it now lives in frontend.handler.db-based.import-edn-dialog-test, which carries the requires and the sample EDN it needs, and import_test.cljs is back to master's.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
…mmits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 1, 2026
…mmits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 2, 2026
…mmits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
…ace, so it merges cleanly with logseq#13886

The test this PR added to import_test.cljs sat at the same place as the ones logseq#13886 adds there, so the two PRs conflicted and the nightly merge left one of them out. The test is unchanged; it now lives in frontend.handler.db-based.import-edn-dialog-test, which carries the requires and the sample EDN it needs, and import_test.cljs is back to master's.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
…mmits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 4, 2026
…mmits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 11, 2026
…ace, so it merges cleanly with logseq#13886

The test this PR added to import_test.cljs sat at the same place as the ones logseq#13886 adds there, so the two PRs conflicted and the nightly merge left one of them out. The test is unchanged; it now lives in frontend.handler.db-based.import-edn-dialog-test, which carries the requires and the sample EDN it needs, and import_test.cljs is back to master's.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 11, 2026
…mmits conflicted one by one with the stack)
Importing a file graph with "Import all tags" produced an invalid entity that
was both a class and a property when a tag and a property had the same name in
a file, for example `#scheduled` on one block and `scheduled:: true` on
another. The import reported invalid blocks and the entity could not be
deleted.

The import creates a separate class and property page for the two. The page
of the property is created from the ref page of the name, which can carry the
class attributes of the tag. Its properties are saved for the property page,
including `:logseq.property.class/extends`, which a property cannot have.

The properties saved for a property page no longer include
`:logseq.property.class/extends`.

The test imports a file with a tag and a property of the same name, for a
name of a built-in property and for another name.

Fixes logseq/db-test#1009
Importing a file graph that has a page with a `template::` property, for
example a page file that starts with `template:: tt`, failed with "No property
schema found for nil" and nothing was imported.

Templates are blocks in a DB graph, and the importer converts the template
property of a block into a Template block. The template property of a page was
mapped to a DB property that does not exist, which left a nil property ident.

The importer now ignores `template::` and `template-including-parent::` on a
page and reports them in the ignored properties, like the other file
properties that have no DB equivalent.

The test imports a page with a template property.
…he title

Importing a block with `SCHEDULED:` or `DEADLINE:` on the line after its title
and properties after that left the property lines in the block title, so the
text was both in the title and in the properties:

    - planned block
      SCHEDULED: <2026-01-05 Mon>
      kind:: v1

became a block titled "planned block\nkind:: v1" with the property `kind`.

The importer removes properties from a block title only when they directly
follow the first line, and it removed the planning lines after that.

It now removes the planning lines first, so the properties follow the first
line when the properties are removed.

The test imports a block with planning lines and properties.
Importing a block whose first line is a table left the properties after it in
the block title, so the text was both in the title and in the properties:

    - | a | b |
      |---|---|
      | c | d |
      key:: v

The importer removes properties from a block title only when they directly
follow the first line, which is the case for a title of one line, but not for a
table of several lines.

When the block starts with table lines, the properties are now removed after
those lines.

The test removes properties after a table, and keeps the lines of a block whose
first line is text.
…iles use text

Importing a file graph in which a property is a checkbox or a number in one
file and text in a later file failed on the later file with "Expected number
or lookup ref for entity id, got nil", and that file was skipped:

    a.md   - x
             rating:: true
    b.md   - y
             rating:: text1

The importer changes the type of the property to text and rewrites the values
that exist. It retracted the old values as entities, which is right for a text
value but not for a checkbox or a number, which are stored as the value itself,
so it retracted the entity nil.

The importer now retracts a value that is an entity as an entity and any
other value as a value of the property.

The tests import the file pairs above, once with the boolean on a block and
once with it on a page.
Importing a block with a property whose value is a block ref,
`rating:: ((<uuid>))`, kept the literal `((uuid))` in the property value. The
value showed the text of the ref instead of the referenced block, and it was
not a reference of the block that it points to.

The importer converts `((uuid))` to `[[uuid]]` in block titles, but the text of
a property value block was not converted.

The importer now converts block refs in the text of property value blocks and
adds the refs to them.

The test imports a block ref in a property value, and one to a block that does
not exist.
Importing a file in which a block other than the first has a `title::`
property renamed the whole page to that title. A journal page was not created
at all, and its blocks went to a page with the title of the block.

    - a1
    - b1
      title:: xt

The importer took the page name from the first properties node anywhere in the
file, including the properties of a block.

The importer now takes the page name only from the page properties, which come
before the first block.

The test imports a page and a journal with a title property on a block, and a
page that has a title property of its own.
…class

Importing a file graph with "Import all tags" created a second page for a
namespaced tag when the tag's page already existed as a namespace page:

    ns___a___b.md   - x1
    other.md        - o1 #ns/a

The page `a` under `ns` stayed a page with the child `ns/a/b`, and a separate
class `a` was created for the tag, so the block was tagged with a node other
than the one the namespace is built on.

The importer only looked for an existing class by the name and the namespace
of the tag. When the tag has no class but there is a page with that namespaced
name, the tag is now converted into the class on that page, so the page, the
class and the namespace are one node.

The test imports the two files above.
…ated the page

The import still produced an entity that was both a class and a property in
one case of logseq/db-test#1009: a file referenced the page of a name, and a
later file had a page of that name that is the tag `tags:: [[scheduled]]` of a
block and also the property `scheduled:: true` of another.

The page of the name existed from the first file. The later file turned it into
a class, and the import also turned the existing page into the property,
because it only knew that a page was a class when an earlier import had made
it one.

An existing page that becomes a class in the file now keeps being the class and
the property gets its own entity, like when the class exists already.

The test imports the two files above.

Fixes logseq/db-test#1009
…of the import

The previous change that turns `((uuid))` in a property value into `[[uuid]]`
also added the ref to the value block. When the referenced block is imported
in a later file, the ref pointed at a block that did not exist yet, and the
import failed with "Nothing found for entity id [:block/uuid ...]".

The refs of a block are built from its title when the import is finalized, as
for the title of any block, which works for a block that is imported later.

The importer now only converts the text of the property value block.
…it-pages-and-properties-tx stays under the large-vars limit
…blocks, so db.cljs merges cleanly with logseq#13786

The check this PR added to ldb/transact! for an EDN import's tx-meta sat on the same lines as the one logseq#13786 adds there (whether to expand and clean up deletes), so the two PRs conflicted and the nightly merge left one of them out. transact! is back to master's; expand-delete-blocks-tx and update-refs-history, which it passes tx-meta to, now do nothing for an import. Same behaviour for the import, so nothing changes for the user.
… own page

Importing a file graph with the pages projects/b and b gave no root page b when projects/b was mentioned in an earlier file. Every later [[b]] linked to projects/b, and the blocks of pages/b.md were appended to projects/b. With the files in the other order the import made two pages, so the result depended on file names.

The db stores the namespace page projects/b with the name b. Three name lookups in the import found it by the bare name b: the page uuid from extract, the existing-page fallback in lookup-imported-page-uuid and the page entity in page-name-string->map. The import's own name index keys namespace pages by their full name, so these db lookups were the only path that matched.

When importing, gp-block/get-page now skips pages with a namespace parent, and the three lookups use it.

Test: exporter-page-merge-test imports a/b before b, and a [[projects/b]] ref before a [[b]] ref, and checks there are two pages with their own blocks and refs.
…l #Page

Importing a file graph with journals/2023_06_21.md and pages/Jun 21st, 2023.md gave a journal page tagged both #Journal and #Page. The page failed validation ("should not have other built-in page tags when tagged with #Page"), and every later write to it, including deleting it, failed with "DB write failed with invalid data".

The journal file creates the page with #Journal first. For the page file, build-existing-page runs update-page-tags on the incoming page map, which adds #Page when the incoming tags have no page class. It does not look at the tags the existing page already has.

build-existing-page now leaves #Page out when the existing page already has another page class (#Journal, #Whiteboard, a tag or property).

Test: exporter-page-merge-test imports a journal file and a page file for the same date, with and without page tags, and checks the page is a journal without #Page, the graph validates and the page can be deleted.

Fixes logseq/db-test#1378
With pages/b.md, pages/projects___sub___b.md and pages/sub___b.md, the import resolved the parent sub of sub/b to projects/sub, so there was no page sub and two pages b under projects/sub. The fix for the namespace page lookup by bare name also covers this parent lookup; this test pins it.
With pages/Jun 21st, 2023.md imported before journals/2023_06_21.md, master also gave a journal tagged #Journal and #Page that did not validate and could not be deleted. The page file creates the journal page, and the journal file then adds #Page through build-existing-page, which the fix for logseq/db-test#1378 now prevents. This test pins that order.
…to a class

With convert-all-tags? on (the import's default), a block with #[[Dec 31st, 2025]] turned the journal page for that day into a class: tagged #Journal and #Tag, with a user class ident. The graph failed validation (journal-day is not allowed on a class).

convert-tag? decided by the tag's name only, so a journal day was converted like any other tag.

convert-tag? now takes the tag page and does not convert a journal day. The tag stays a ref to the journal page, as it does with convert-all-tags? off.

Test: exporter-convert-tags-test imports #[[Dec 31st, 2025]] with and without the journal file and checks the journal is not a class, the block refs it and the graph validates.
…ay one page each

The file-graph importer still merged or doubled pages in import orders the earlier fixes did not cover:
- A pages/ file named like a journal file of the import (pages/Dec 31st, 2025.md next to journals/2025_12_31.md), imported first in a graph whose config.edn has no journal title format, became a plain page. The journal file then merged into it: a page tagged #Journal and #Page without a journal day, its blocks on no page, refs pointing elsewhere, and deleting it failed with "DB write failed with invalid data".
- With convert-all-tags? on, #projects/x made a class x that extends projects. A later pages/x.md or [[x]] found that class by the bare name x, so the root page x was never created and its blocks went to the class.
- With convert-all-tags? on, [[work/b]] and then #work/b made a page b and a class b, both under work.

Causes: the page file is not recognized as a journal without the title format, while the import indexes journal files by their canonical title. A namespaced class has no :block/parent, only an extends, so the namespace-child check in the bare-name lookup missed it; the import's name index also keyed the class's page map, saved without its parent, by its bare name, and read :block/tags with contains?, which is false on the vector a new class carries. The class built for #work/b took the tag's own new uuid instead of the uuid of the page work/b already in the index.

Changes: a page whose name is a journal file of the import becomes that journal (uuid, journal day, #Journal) before it is built. gp-block/get-page skips classes that extend a class other than Root. The name index skips the bare name of a uuid that is also saved under its full name, and reads tags as a collection. A namespaced tag converted to a class takes the uuid of the page of that full name when there is one, so the page becomes the class.

Tests: exporter-page-merge-test imports a page file before its journal file through export-file-graph with a config.edn without a journal title format; exporter-convert-tags-test imports #projects/x before pages/x.md and [[x]], and [[work/b]] before #work/b. All fail on the previous commit. The importer collision fuzzer has 0 journal-and-page-tag and 0 page-duplicate failures in seeds 1-20.
A page file with alias:: [[Jan 5th, 2026]] imported before journals/2026_01_05.md made the whole import fail with "Nothing found for entity id [:block/uuid #uuid "00000001-2026-0105-0000-000000000000"]".

The import gives a journal of the import its uuid before the journal file is imported, and update-page-alias wrote each alias as a [:block/uuid ..] lookup ref, which fails when that page does not exist yet.

The alias is now a {:block/uuid ..} map, which the journal file later fills in, as block refs already are.

Test: exporter-page-merge-test imports the aliasing page before the journal file through export-file-graph and checks the alias is the journal and the graph validates. It fails on the previous commit.
With convert-all-tags? on (the import's default), #x or tags:: x in a file imported after #work/x went to the class work/x. The block's tag and the page's tags then depended on the file order: the same graph imported in another order tagged it with a class x, and the page x was a #Tag in one order and a #Page in the other.

find-existing-class looked up a tag without a namespace by its name only. A namespaced class work/x is stored with the name x and extends work, so it matched.

That lookup now skips namespaced classes, as the page lookups by bare name already do.

Test: exporter-convert-tags-test imports #work/x before #x and checks that x is its own root class. It fails on the previous commit.
A pages/ file named like a journal day (pages/Jan 5th, 2026.md) with no journal file for that day was a plain page when it was imported first. A later [[Jan 5th, 2026]] or alias:: [[Jan 5th, 2026]] in another file is a journal ref and added #Journal to that page: a page tagged #Journal and #Page without a journal day, which fails validation and cannot be deleted. With the other file first, the import made a valid journal.

The importer reads pages/ files with skip-journal?, so their titles are not converted to journals, while refs and aliases to the same name are.

The page of a pages/ file whose title is a journal title in the graph's format, or the title of a journal file of the import, is now built as that journal (journal uuid, day and canonical name, #Journal instead of #Page). This replaces the earlier rule that only covered names of journal files of the import.

Test: exporter-page-merge-test imports pages/Jan 5th, 2026.md before a page that aliases it, through export-file-graph, and checks there is one valid journal holding the page file's block. It fails on the previous commit.
…eplace part of it

`- x #A/B #a` imported as `x [[a]]/B [[a]]`: the block lost its link to A/B
and showed a broken `/B`. Tags are replaced ignoring case and as plain text,
in the order sort-refs gives, which compares titles case-sensitively and put
"a" before "A/B", so `#a` replaced the `#A` of `#A/B`. The same held for
`#Foo-bar #foo`. Tags are now replaced longest title first (nested page
titles still first), so a tag that is the start of another is replaced after
it. Found by the importer collision fuzzer on the nightly (seed 4024);
master has it too.
… that still fails

export-file-graph-fails-fast-with-relative-path-and-reason (from master) made pages/T.md fail with a page `template::` property and pages/B.md with a boolean property later used as text. This branch fixes both, so those files now import and the test saw no failure. Both page files now use the query-sort-by input of the journal case, which still fails; the assertions on the error's path and reason are unchanged.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
…ace, so it merges cleanly with logseq#13886

The test this PR added to import_test.cljs sat at the same place as the ones logseq#13886 adds there, so the two PRs conflicted and the nightly merge left one of them out. The test is unchanged; it now lives in frontend.handler.db-based.import-edn-dialog-test, which carries the requires and the sample EDN it needs, and import_test.cljs is back to master's.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
…mmits conflicted one by one with the stack)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment