Skip to content

Commit c2f4b63

Browse files
fix: preserve permalink when editing notes without frontmatter permalink (#184)
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
1 parent 46d102c commit c2f4b63

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/basic_memory/markdown/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def entity_model_from_markdown(
3838
# Update basic fields
3939
model.title = markdown.frontmatter.title
4040
model.entity_type = markdown.frontmatter.type
41-
model.permalink = markdown.frontmatter.permalink
41+
# Only update permalink if it exists in frontmatter, otherwise preserve existing
42+
if markdown.frontmatter.permalink is not None:
43+
model.permalink = markdown.frontmatter.permalink
4244
model.file_path = str(file_path)
4345
model.content_type = "text/markdown"
4446
model.created_at = markdown.created

tests/mcp/test_tool_edit_note.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,42 @@ async def test_edit_note_find_replace_empty_find_text(client):
359359
assert isinstance(result, str)
360360
assert "# Edit Failed" in result
361361
# Should contain helpful guidance about the error
362+
363+
364+
@pytest.mark.asyncio
365+
async def test_edit_note_preserves_permalink_when_frontmatter_missing(client):
366+
"""Test that editing a note preserves the permalink when frontmatter doesn't contain one.
367+
368+
This is a regression test for issue #170 where edit_note would fail with a validation error
369+
because the permalink was being set to None when the markdown file didn't have a permalink
370+
in its frontmatter.
371+
"""
372+
# Create initial note
373+
await write_note.fn(
374+
title="Test Note",
375+
folder="test",
376+
content="# Test Note\nOriginal content here.",
377+
)
378+
379+
# Verify the note was created with a permalink
380+
first_result = await edit_note.fn(
381+
identifier="test/test-note",
382+
operation="append",
383+
content="\nFirst edit.",
384+
)
385+
386+
assert isinstance(first_result, str)
387+
assert "permalink: test/test-note" in first_result
388+
389+
# Perform another edit - this should preserve the permalink even if the
390+
# file doesn't have a permalink in its frontmatter
391+
second_result = await edit_note.fn(
392+
identifier="test/test-note",
393+
operation="append",
394+
content="\nSecond edit.",
395+
)
396+
397+
assert isinstance(second_result, str)
398+
assert "Edited note (append)" in second_result
399+
assert "permalink: test/test-note" in second_result
400+
# The edit should succeed without validation errors

0 commit comments

Comments
 (0)