Skip to content

Commit cd8e372

Browse files
phernandezclaude
andcommitted
fix: add test coverage for optional permalink in EntityResponse schema
- Add comprehensive test for None permalink validation in EntityResponse - Ensures schema properly handles markdown files without explicit permalinks - Addresses GitHub issue #170 validation errors during edit operations - Test validates that permalink=None doesn't cause ValidationError 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent a589f8b commit cd8e372

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/basic_memory/schemas/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class EntityResponse(SQLAlchemyModel):
131131
}
132132
"""
133133

134-
permalink: Permalink
134+
permalink: Optional[Permalink]
135135
title: str
136136
file_path: str
137137
entity_type: EntityType

tests/schemas/test_schemas.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ def test_entity_out_from_attributes():
127127
assert len(entity.relations) == 1
128128

129129

130+
def test_entity_response_with_none_permalink():
131+
"""Test EntityResponse can handle None permalink (fixes issue #170).
132+
133+
This test ensures that EntityResponse properly validates when the permalink
134+
field is None, which can occur when markdown files don't have explicit
135+
permalinks in their frontmatter during edit operations.
136+
"""
137+
# Simulate database model attributes with None permalink
138+
db_data = {
139+
"title": "Test Entity",
140+
"permalink": None, # This should not cause validation errors
141+
"file_path": "test/test-entity.md",
142+
"entity_type": "note",
143+
"content_type": "text/markdown",
144+
"observations": [],
145+
"relations": [],
146+
"created_at": "2023-01-01T00:00:00",
147+
"updated_at": "2023-01-01T00:00:00",
148+
}
149+
150+
# This should not raise a ValidationError
151+
entity = EntityResponse.model_validate(db_data)
152+
assert entity.permalink is None
153+
assert entity.title == "Test Entity"
154+
assert entity.file_path == "test/test-entity.md"
155+
assert entity.entity_type == "note"
156+
assert len(entity.observations) == 0
157+
assert len(entity.relations) == 0
158+
159+
130160
def test_search_nodes_input():
131161
"""Test SearchNodesInput validation."""
132162
search = SearchNodesRequest.model_validate({"query": "test query"})

0 commit comments

Comments
 (0)