You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Validation error moving a file in basic memory #155
User is encountering validation errors when trying to move a file in basic-memory. The error log shows:
"Error moving entity: 1 validation error for EntityResponse permalink - Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]"
The move operation fails when attempting to move 'Finanza/Financial Analysis/Mastercard (MA) Financial Analysis - May 2025.md' to 'Finanza/Settori/Financial/Mastercard (MA) Financial Analysis - May 2025.md'.
I noticed in my config.json file that "update_permalinks_on_move" is currently set to false. Would changing this setting to true resolve this validation error? I'd appreciate your guidance on the correct configuration to fix this issue.
I've found the exact cause of the validation error when moving files in basic-memory.
Root Cause
This is a schema mismatch bug between the database and API response validation:
Database Migration: A recent migration (502b60eaa905_remove_required_from_entity_permalink.py) made the permalink column nullable in the database
Response Schema: The EntityResponse.permalink field still requires a non-null string (Permalink = Annotated[str, MinLen(1)])
Move Operation: When update_permalinks_on_move is false, no new permalink is generated, leaving the database value as NULL
Validation Failure: Pydantic validation fails when trying to create an EntityResponse from an entity with permalink=None
Your Config Question
Yes, setting "update_permalinks_on_move": true would resolve this issue because:
It forces generation of a new permalink during the move operation
The entity would have a valid string permalink instead of NULL
The validation would pass
The Real Fix Needed
However, this is a bug that should be fixed in the code. The system should handle entities with NULL permalinks gracefully. Here are the recommended solutions:
Option 1: Make EntityResponse.permalink Optional
# In src/basic_memory/schemas/response.pypermalink: Optional[Permalink] =None
Option 2: Generate Default Permalinks
# In the move_entity method, always ensure permalink existsifnotupdated_entity.permalink:
# Generate permalink from file_pathupdates["permalink"] =awaitself.resolve_permalink(destination_path)
Option 3: Handle NULL in Model Validation
Add a validator to generate permalinks when missing.
Immediate Workaround
For now, you can resolve this by setting "update_permalinks_on_move": true in your config, but this shouldn't be necessary.
Examine current code structure (entity_service.py, schemas/response.py)
Create test that reproduces the validation error
Implement fix to ensure permalinks are generated during move operations
Run test suite to verify fix works
Run linting and type checking
Commit changes to branch
Provide PR link
Summary
Successfully implemented a fix for issue #155 with comprehensive test coverage.
Root Cause: Entities with null permalinks from database migration would fail validation when creating EntityResponse objects during move operations.
Solution: Modified move_entity method to automatically generate permalinks for entities with null permalinks, regardless of the update_permalinks_on_move configuration setting.
Changes Made:
Fix:src/basic_memory/services/entity_service.py - Added null permalink detection and generation
Activity
phernandez commentedon Jun 20, 2025
@claude can you look at this issue and see if you can find what is causing the error?
claude commentedon Jun 20, 2025
Claude finished @phernandez's task —— View job
Analysis Complete - Root Cause Identified ✅
I've found the exact cause of the validation error when moving files in basic-memory.
Root Cause
This is a schema mismatch bug between the database and API response validation:
502b60eaa905_remove_required_from_entity_permalink.py) made thepermalinkcolumn nullable in the databaseEntityResponse.permalinkfield still requires a non-null string (Permalink = Annotated[str, MinLen(1)])update_permalinks_on_moveisfalse, no new permalink is generated, leaving the database value asNULLEntityResponsefrom an entity withpermalink=NoneYour Config Question
Yes, setting
"update_permalinks_on_move": truewould resolve this issue because:NULLThe Real Fix Needed
However, this is a bug that should be fixed in the code. The system should handle entities with
NULLpermalinks gracefully. Here are the recommended solutions:Option 1: Make EntityResponse.permalink Optional
Option 2: Generate Default Permalinks
Option 3: Handle NULL in Model Validation
Add a validator to generate permalinks when missing.
Immediate Workaround
For now, you can resolve this by setting
"update_permalinks_on_move": truein your config, but this shouldn't be necessary.Files Involved
src/basic_memory/schemas/response.py:134- EntityResponse schema validationsrc/basic_memory/services/entity_service.py:626-720- move_entity methodsrc/basic_memory/alembic/versions/502b60eaa905_*- Migration that made permalinks nullableThe migration made the database field nullable but the API schema wasn't updated to match, creating this validation mismatch.
phernandez commentedon Jun 20, 2025
@claude Nice find. Can you make a PR that has a test and also a fix?
claude commentedon Jun 20, 2025
Claude finished @phernandez's task —— View job •
claude/issue-155-20250620_134617• Create PR ➔Creating PR with Test and Fix ✅
Todo List:
Summary
Successfully implemented a fix for issue #155 with comprehensive test coverage.
Root Cause: Entities with
nullpermalinks from database migration would fail validation when creatingEntityResponseobjects during move operations.Solution: Modified
move_entitymethod to automatically generate permalinks for entities withnullpermalinks, regardless of theupdate_permalinks_on_moveconfiguration setting.Changes Made:
src/basic_memory/services/entity_service.py- Added null permalink detection and generationtests/services/test_entity_service.py- Addedtest_move_entity_with_null_permalink_generates_permalinkKey Benefits:
fix: ensure permalinks are generated for entities with null permalink…