fix: handle missing 'name' key in memory JSON import#241
Merged
Conversation
Fixes KeyError when importing memory.json files that use different identifier keys (id, entityName) instead of 'name'. This commonly occurs with files from Knowledge Graph Memory Server. Changes: - Add robust key handling to try name/entityName/id as fallback options - Add fallback handling for entityType and observations fields - Track and display count of skipped entities with missing identifiers - Add comprehensive test coverage for missing name key scenarios The importer now gracefully handles various JSON structures while maintaining backward compatibility with existing formats. Fixes #232 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: jope-bm <jope-bm@users.noreply.github.com> Signed-off-by: Joe P <joe@basicmemory.com>
Apply automatic code formatting and linting fixes from ruff formatter. These changes ensure consistent code style across the codebase without functional modifications. Changes: - Fix whitespace and line ending consistency - Apply consistent string quote formatting - Remove trailing whitespace - Format multi-line expressions for better readability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: jope-bm <jope-bm@users.noreply.github.com> Signed-off-by: Joe P <joe@basicmemory.com>
jope-bm
commented
Jul 28, 2025
| if data["type"] == "entity": | ||
| entities[data["name"]] = data | ||
| # Handle different possible name keys | ||
| entity_name = data.get("name") or data.get("entityName") or data.get("id") |
Contributor
Author
There was a problem hiding this comment.
though I haven't encountered a memory.json with "id" in entity, Claude seems to think it's possible.
phernandez
approved these changes
Jul 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Summary
Changes
import_memory_json()insrc/basic_memory/cli/import_command.pyto handle missing 'name' key gracefullyTest plan
Fixes #232
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com