Skip to content

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

Closed
yuxi-liu-wired wants to merge 15 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-importer
Closed

yuxi-liu-wired wants to merge 15 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-importer

Conversation

@yuxi-liu-wired

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

Copy link
Copy Markdown
Contributor

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

Importing a file graph dropped a table that sat inside a quote. A block like
`#+BEGIN_QUOTE`, some text and a markdown table became a block with only the
text, and the import logged "Ignored ast node" for the table.

The importer turns the content of quotes into the block title with
`ast->text`, which had no branch for a Table node, so it ignored the table.

`ast->text` now writes a Table node as a markdown table, one row per line,
with a header separator row.

The test imports a quote block that contains a table.

Fixes logseq/db-test#1048
Importing a file graph whose Zotero notes point at a linked PDF with an
absolute path, `{{zotero-linked-file "/home/me/papers/foo.pdf"}}`, did not
create the PDF's asset when the graph has a Zotero linked attachment base
directory. The link was left without an asset and nothing was reported.

The importer joined the base directory with the path of the macro, so it
looked for `<base>/home/me/papers/foo.pdf`, which does not exist. Zotero
writes a relative path only for a file inside the base directory.

The importer now uses the path of the macro as is when it is absolute
(including a Windows drive path) and joins it with the base directory only
when it is relative.

The test imports a page with a linked file outside the base directory.

Fixes logseq/db-test#1408
Importing a file graph with a Zotero PDF that is not on disk, for example one
that Zotero renamed, dropped the PDF's asset. The annotations of the PDF were
dropped with it and the blocks that referenced them lost their references.
In the reported graph this ended with an import that failed on a dangling
block reference and left an empty graph.

When the importer cannot stat a PDF it still creates the asset if the PDF is
an external reference (a `file://` link, a Windows path or an http URL), but
not for a Zotero PDF, which is just as external: its asset only points at the
Zotero item.

The importer now treats a Zotero PDF like the other external PDFs and creates
its asset when the stat fails.

The test imports a Zotero linked PDF that does not exist, with an annotation
page and a block that references the annotation.

Fixes logseq/db-test#1469

@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 1 potential issue.

Devin Review

Comment on lines +1789 to +1792
(if (or (node-path/isAbsolute linked-relative)
(windows-drive-path? linked-relative))
linked-relative
(node-path/join linked-base-dir linked-relative)))

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.

🔴 Imported absolute Zotero PDFs cannot open

For a Zotero PDF outside its base directory, resolve-asset-data stores an absolute zotero-link:// path. get-zotero-local-pdf-path joins it to the base directory, so opening the imported PDF fails.

Learn more

The importer records the macro's absolute filename in :logseq.property.asset/external-file-name as zotero-link://<absolute path>. The PDF open path get-zotero-local-pdf-path strips the scheme and always calls node-path.join with the configured base directory. Node's path.join does not discard the base directory for an absolute second argument, so the viewer resolves a different filename. Both open-pdf-file and db-based-open-block-ref! rely on this resolver.

Example: With base /library/base and a linked PDF at /library/elsewhere/Foo.pdf, import stores zotero-link:///library/elsewhere/Foo.pdf. Opening it looks for /library/base/library/elsewhere/Foo.pdf instead of the existing PDF.

Recommended fix: Update the shared get-zotero-local-pdf-path resolver to return an absolute linked path unchanged and join only relative paths. Cover opening the newly imported asset and an annotation reference, not only its stored metadata.

Devin Review


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

Opening an imported Zotero PDF, or an annotation of it, failed when the PDF
is a linked file outside the Zotero base directory. The viewer looked for it
in `<base directory>/<absolute path>`.

The file graph import keeps the path of such a file as
`zotero-link://<absolute path>`, but `get-zotero-local-pdf-path` always joined
what follows the scheme with the base directory, which is right only for a
path relative to it.

`get-zotero-local-pdf-path` now returns an absolute path as it is (including
a Windows drive path) and joins only a relative path with the base directory.

The test calls it with a relative path, a posix absolute path, a Windows
drive path and a Zotero storage path.

Fixes logseq/db-test#1408
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
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Good catch. The importer writes zotero-link://<absolute path> for a linked file outside the base directory, but get-zotero-local-pdf-path (src/main/frontend/extensions/pdf/assets.cljs) always joined the part after the scheme with the base directory, so opening the PDF, or an annotation of it through db-based-open-block-ref!, looked in <base>/<absolute path>. Fixed in a separate commit on this branch: the resolver now returns an absolute path as it is (a posix absolute path or a Windows drive path) and joins only a relative path with the base directory. zotero-path:// (Zotero storage) is unchanged. get-zotero-local-pdf-path-test covers a relative path, a posix absolute path, a Windows drive path and a storage path; without the change the two absolute-path cases fail, and the whole unit suite passes with it.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined into #13886 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/dbtest-importer branch November 17, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment