fix: sanitize get-blocks worker results#12884
Open
megayu wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens the db worker’s :thread-api/get-blocks boundary by sanitizing block payloads returned to the renderer, preventing d/transact! failures caused by nil-valued attributes in malformed block maps.
Changes:
- Added
sanitize-block-resultto strip nil-valued entries from:blockand each map in:childrenbefore Transit serialization. - Applied sanitization to the
get-blocks-with-cachepath so cached responses are also cleaned. - Added a unit test ensuring nil-valued keys are removed from both the parent block and children blocks in the worker response.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/main/frontend/worker/db_core.cljs | Sanitizes :thread-api/get-blocks results to avoid returning nil-valued attributes to the renderer. |
| src/test/frontend/worker/db_core_test.cljs | Adds coverage asserting nil-valued keys are removed from returned :block and :children maps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This partially addresses logseq/db-test#974.
The issue reports a blank page caused by
Cannot store nil as a valuewhen rendering a page that contains a malformed block. The reported entity had:block/pageset but:block/parent nil. That data shape is invalid for a block, and DataScript rejects re-transacting a map that contains nil-valued attributes.This change does not try to identify or fix the original source of the malformed data. Instead, it hardens the worker
:thread-api/get-blocksresponse boundary by removing nil-valued entries from returned:blockand:childrenmaps before they are serialized back to the renderer. This prevents lazy-loaded/query/table block results from carrying maps such as{:block/parent nil}into renderer-sided/transact!.Existing graph repair remains the responsibility of graph validation, for example
logseq graph validate --graph <graph> --fix, which already has logic to repair blocks that have:block/pagebut no:block/parent.