From 5bd2a6d948d639ecc23e216d772e8ae998f54bf3 Mon Sep 17 00:00:00 2001 From: Atharvsinh-codez Date: Sun, 4 Oct 2026 18:46:50 +0000 Subject: [PATCH] fix(openai-sdk-python): don't fail get_profile for users with no memories The API returns a null profile for a user who has no stored memories yet (the same case as #1027 for the pipecat package). get_profile passed it straight to _model_to_dict, which raises TypeError for None, so the tool came back as success=False with "Profile fetch failed: Unsupported SDK response type: NoneType" for every new user. Return an empty profile ({"static": [], "dynamic": []}) in that case, like the cartesia and pipecat packages already do. Added a test for the null-profile response. --- .../src/supermemory_openai/tools.py | 7 ++++++- packages/openai-sdk-python/tests/test_tools.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/openai-sdk-python/src/supermemory_openai/tools.py b/packages/openai-sdk-python/src/supermemory_openai/tools.py index bad75e8a3..ef5375f90 100644 --- a/packages/openai-sdk-python/src/supermemory_openai/tools.py +++ b/packages/openai-sdk-python/src/supermemory_openai/tools.py @@ -528,7 +528,12 @@ async def get_profile( return ProfileResult( success=True, - profile=_model_to_dict(response.profile), + # The API returns a null profile for a user with no memories yet. + profile=( + _model_to_dict(response.profile) + if response.profile is not None + else {"static": [], "dynamic": []} + ), search_results=( _model_to_dict(response.search_results) if response.search_results is not None diff --git a/packages/openai-sdk-python/tests/test_tools.py b/packages/openai-sdk-python/tests/test_tools.py index 4680a9a21..b0fa1ec0c 100644 --- a/packages/openai-sdk-python/tests/test_tools.py +++ b/packages/openai-sdk-python/tests/test_tools.py @@ -255,6 +255,23 @@ async def test_get_profile_uses_client_profile(self): q="tea", ) + @pytest.mark.asyncio + async def test_get_profile_handles_user_with_no_memories(self): + """A null profile (new user, no memories yet) is an empty profile, not a failure.""" + from types import SimpleNamespace + from unittest.mock import AsyncMock + + tools = SupermemoryTools("test-key", {"container_tags": ["unit-tag"]}) + tools.client.profile = AsyncMock( + return_value=SimpleNamespace(profile=None, search_results=None) + ) + + result = await tools.get_profile() + + assert result["success"] is True + assert result["profile"] == {"static": [], "dynamic": []} + assert result["search_results"] is None + @pytest.mark.asyncio async def test_document_list_uses_client_documents_list(self): """document_list must call client.documents.list with container tag."""