Compare commits

...

1 Commits

Author SHA1 Message Date
claude[bot] b57cb3a785 fix: Handle None text values in Claude conversations importer
- Add robust handling for None text values in content array
- Filter out None values before joining text content
- Ensure all text values are converted to strings
- Add comprehensive test case for None text values scenario

Fixes #236

Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
2025-09-26 14:52:03 +00:00
2 changed files with 59 additions and 1 deletions
@@ -153,7 +153,14 @@ 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 and ensure all items are strings
valid_content = []
for c in msg["content"]:
if c and isinstance(c, dict):
text = c.get("text")
if text is not None:
valid_content.append(str(text))
content = " ".join(valid_content) if valid_content else ""
lines.append(content)
# Handle attachments
@@ -149,3 +149,54 @@ 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."""
# Create conversation with None text values (reproduces bug from issue #236)
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": "Message with mixed content",
"sender": "human",
"created_at": "2025-01-05T20:55:32.499880+00:00",
"content": [
{"type": "text", "text": "Valid text here"},
{"type": "text", "text": None}, # This causes the TypeError
{"type": "text", "text": "More valid text"},
],
},
{
"uuid": "msg-2",
"text": "Response",
"sender": "assistant",
"created_at": "2025-01-05T20:55:40.123456+00:00",
"content": [
{"type": "text", "text": None}, # All None case
],
},
],
}
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()
# Set up environment
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
assert "Import complete" in result.output
# Check that valid text was preserved
conv_path = tmp_path / "conversations/20250105-Test_With_None_Text.md"
content = conv_path.read_text(encoding="utf-8")
assert "Valid text here More valid text" in content # None values filtered out