From bd6c8348b8fe8a8cafe7cda89eb22880acebf0c3 Mon Sep 17 00:00:00 2001 From: Paul Hernandez <60959+phernandez@users.noreply.github.com> Date: Wed, 15 Oct 2025 16:08:57 -0500 Subject: [PATCH] fix: Handle None text values in Claude conversations importer (#353) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Paul Hernandez --- .../claude_conversations_importer.py | 6 ++- tests/cli/test_import_claude_conversations.py | 52 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/basic_memory/importers/claude_conversations_importer.py b/src/basic_memory/importers/claude_conversations_importer.py index 0888c8e6..de7dc958 100644 --- a/src/basic_memory/importers/claude_conversations_importer.py +++ b/src/basic_memory/importers/claude_conversations_importer.py @@ -153,7 +153,11 @@ class ClaudeConversationsImporter(Importer[ChatImportResult]): # Handle message content content = msg.get("text", "") if msg.get("content"): - content = " ".join(c.get("text", "") for c in msg["content"]) + # Filter out None values before joining + content = " ".join( + str(c.get("text", "")) for c in msg["content"] + if c and c.get("text") is not None + ) lines.append(content) # Handle attachments diff --git a/tests/cli/test_import_claude_conversations.py b/tests/cli/test_import_claude_conversations.py index c0c77381..7e8e5352 100644 --- a/tests/cli/test_import_claude_conversations.py +++ b/tests/cli/test_import_claude_conversations.py @@ -149,3 +149,55 @@ def test_import_conversation_with_attachments(tmp_path): assert "**Attachment: test.txt**" in content assert "```" in content assert "Test file content" in content + + +def test_import_conversation_with_none_text_values(tmp_path): + """Test importing conversation with None text values in content array (issue #236).""" + # Create conversation with None text values + conversation = { + "uuid": "test-uuid", + "name": "Test With None Text", + "created_at": "2025-01-05T20:55:32.499880+00:00", + "updated_at": "2025-01-05T20:56:39.477600+00:00", + "chat_messages": [ + { + "uuid": "msg-1", + "text": None, + "sender": "human", + "created_at": "2025-01-05T20:55:32.499880+00:00", + "content": [ + {"type": "text", "text": "Valid text here"}, + {"type": "text", "text": None}, # This caused the TypeError + {"type": "text", "text": "More valid text"}, + ], + }, + { + "uuid": "msg-2", + "text": None, + "sender": "assistant", + "created_at": "2025-01-05T20:55:40.123456+00:00", + "content": [ + {"type": "text", "text": None}, # All None case + {"type": "text", "text": None}, + ], + }, + ], + } + + json_file = tmp_path / "with_none_text.json" + with open(json_file, "w", encoding="utf-8") as f: + json.dump([conversation], f) + + config = get_project_config() + config.home = tmp_path + + # Run import - should not fail with TypeError + result = runner.invoke(app, ["import", "claude", "conversations", str(json_file)]) + assert result.exit_code == 0 + + # Check that valid text is preserved and None values are filtered out + conv_path = tmp_path / "conversations/20250105-Test_With_None_Text.md" + assert conv_path.exists() + content = conv_path.read_text(encoding="utf-8") + assert "Valid text here" in content + assert "More valid text" in content