Compare commits

...

1 Commits

Author SHA1 Message Date
claude[bot] df6bcac3b8 fix: Handle null and empty title in markdown frontmatter (#387)
Fixes bug where entities with null or empty titles in frontmatter
caused SQL INSERT failures. The parser now properly falls back to
the filename stem when title is None or empty, matching the behavior
for the type field.

- Updated entity_parser.py to check for None/empty title values
- Added regression tests for null and empty title cases
- References issue #387

Co-authored-by: Drew Cain <groksrc@users.noreply.github.com>
2025-10-20 19:14:59 +00:00
2 changed files with 59 additions and 2 deletions
+4 -2
View File
@@ -129,8 +129,10 @@ class EntityParser:
file_stats = absolute_path.stat()
metadata = post.metadata
# Ensure required fields have defaults (issue #184)
metadata["title"] = post.metadata.get("title", absolute_path.stem)
# Ensure required fields have defaults (issue #184, #387)
# Handle title - use default if missing OR explicitly set to None/null/empty
title = post.metadata.get("title")
metadata["title"] = title if title else absolute_path.stem
# Handle type - use default if missing OR explicitly set to None/null
entity_type = post.metadata.get("type")
metadata["type"] = entity_type if entity_type is not None else "note"
@@ -183,6 +183,61 @@ async def test_parse_file_with_null_entity_type(tmp_path):
assert result.frontmatter.title == "Test File"
@pytest.mark.asyncio
async def test_parse_file_with_null_title(tmp_path):
"""Test that files with explicit null title get default from filename (issue #387).
This reproduces the production error where title was None, causing SQL INSERT to fail.
"""
# Create a file with null/None title
test_file = tmp_path / "null_title.md"
content = dedent(
"""
---
title: null
type: note
---
# Content
"""
).strip()
test_file.write_text(content)
# Parse the file
parser = EntityParser(tmp_path)
result = await parser.parse_file(test_file)
# Should have default title from filename even when explicitly set to null
assert result is not None
assert result.frontmatter.title == "null_title" # Default from filename
assert result.frontmatter.type == "note"
@pytest.mark.asyncio
async def test_parse_file_with_empty_title(tmp_path):
"""Test that files with empty title get default from filename (issue #387)."""
# Create a file with empty title
test_file = tmp_path / "empty_title.md"
content = dedent(
"""
---
title:
type: note
---
# Content
"""
).strip()
test_file.write_text(content)
# Parse the file
parser = EntityParser(tmp_path)
result = await parser.parse_file(test_file)
# Should have default title from filename even when empty
assert result is not None
assert result.frontmatter.title == "empty_title" # Default from filename
assert result.frontmatter.type == "note"
@pytest.mark.asyncio
async def test_parse_valid_file_still_works(tmp_path):
"""Test that valid files with proper frontmatter still parse correctly."""