fix(storage): JSON-serialize date/datetime metadata from YAML frontmatter#25
Open
pk8189 wants to merge 1 commit into
Open
fix(storage): JSON-serialize date/datetime metadata from YAML frontmatter#25pk8189 wants to merge 1 commit into
pk8189 wants to merge 1 commit into
Conversation
…tter
Obsidian and other markdown frontmatter commonly contain `YYYY-MM-DD`
values that PyYAML parses into `datetime.date`, e.g.:
---
last_push: 2026-05-19
---
When `MarkdownParser` extracted the frontmatter and `Database.insert_document`
ran `json.dumps(document.metadata)`, this crashed with:
TypeError: Object of type date is not JSON serializable
Add a small `_json_default` fallback that converts `date` / `datetime`
to ISO strings (and falls back to `str()` for anything else). Round-tripped
values come back as strings — acceptable because metadata is informational
and not queried as dates.
Includes a regression test that fails before this change and passes after,
covering both `insert_document` and `update_document`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
What
Database.insert_documentandupdate_documentcalljson.dumps(document.metadata)to persist parsed-frontmatter metadata. Frontmatter dates likelast_push: 2026-05-19are parsed by PyYAML intodatetime.dateobjects, which the stdlib JSON encoder doesn't know how to handle, so any markdown file with a date in frontmatter fails to index:```
TypeError: Object of type date is not JSON serializable
```
Repro
Hits anyone using Obsidian (very common to have
created: YYYY-MM-DDor similar in frontmatter). A minimal example:```
title: My note
last_push: 2026-05-19
```
`librarian add /path/to/that/note.md` → `Error: ... Object of type date is not JSON serializable`.
Fix
Pass a small `default=` callback to `json.dumps` that converts `date` / `datetime` to ISO strings, and `str()`'s anything else unexpected. Stored as strings; round-tripped values come back as strings — acceptable because metadata is informational, not queried as dates.
Tests
New `tests/test_database.py` with regression tests for both `insert_document` and `update_document`. Verified the tests fail on `main` (reproducing `TypeError`) and pass with this change. Existing `test_parser.py` continues to pass.
Notes