fix: make RelationResponse.from_id optional to handle null permalinks by phernandez · Pull Request #484 · basicmachines-co/basic-memory · GitHub
Skip to content

fix: make RelationResponse.from_id optional to handle null permalinks - #484

Merged
phernandez merged 1 commit into
mainfrom
claude/issue-483-20251229-2348
Dec 30, 2025
Merged

fix: make RelationResponse.from_id optional to handle null permalinks#484
phernandez merged 1 commit into
mainfrom
claude/issue-483-20251229-2348

Conversation

@phernandez

@phernandez phernandez commented Dec 29, 2025

Copy link
Copy Markdown
Member

Fixes #483

When entities are imported from environments where permalinks were not enabled, the from_entity.permalink can be None. This caused Pydantic validation to fail because the AliasChoices approach would find the None value (since the path exists) rather than falling back.

Changes

  • Replaced AliasChoices with a model_validator that properly resolves entity references
  • When permalink is available, use it
  • When permalink is None, fall back to file_path directly
  • Uses file_path as-is (not converted to permalink format) because if the entity doesn't have a permalink, the system won't find it by a generated one anyway
  • Added comprehensive test cases for both scenarios

Why file_path instead of None?

The previous approach made from_id optional and returned None. This loses useful information - the client can't identify the source entity of the relation. Using the actual file_path preserves a real identifier that can be used to find the entity.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

…inks

When entities are imported from environments where permalinks were not
enabled, from_entity.permalink can be None. Previously this caused
Pydantic validation to fail.

This fix uses a model_validator to properly resolve entity references:
- Prefers permalink when available
- Falls back to file_path directly (not converted to permalink format)
  because if the entity doesn't have a permalink, the system won't find
  it by a generated one anyway

Fixes #483

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez force-pushed the claude/issue-483-20251229-2348 branch from bc3b95c to 2ea78f6 Compare December 30, 2025 00:24
@github-actions

github-actions Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

@phernandez
phernandez merged commit 537e58a into main Dec 30, 2025
24 of 27 checks passed
@phernandez
phernandez deleted the claude/issue-483-20251229-2348 branch December 30, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RelationResponse validation fails when from_entity.permalink is null

1 participant