diff --git a/packages/pipecat-sdk-python/src/supermemory_pipecat/service.py b/packages/pipecat-sdk-python/src/supermemory_pipecat/service.py index 2aef866bf..386a0bf4c 100644 --- a/packages/pipecat-sdk-python/src/supermemory_pipecat/service.py +++ b/packages/pipecat-sdk-python/src/supermemory_pipecat/service.py @@ -150,10 +150,13 @@ async def _retrieve_memories(self, query: str) -> Dict[str, Any]: if response.search_results and response.search_results.results: search_results = response.search_results.results + profile_static = response.profile.static if response.profile is not None else [] + profile_dynamic = response.profile.dynamic if response.profile is not None else [] + return { "profile": { - "static": response.profile.static, - "dynamic": response.profile.dynamic, + "static": profile_static, + "dynamic": profile_dynamic, }, "search_results": search_results, } diff --git a/packages/pipecat-sdk-python/tests/test_service_none_profile.py b/packages/pipecat-sdk-python/tests/test_service_none_profile.py new file mode 100644 index 000000000..f5e4bd2c7 --- /dev/null +++ b/packages/pipecat-sdk-python/tests/test_service_none_profile.py @@ -0,0 +1,32 @@ +"""Test that _retrieve_memories handles a None profile without raising AttributeError.""" + +import pytest + + +def test_retrieve_memories_none_profile_returns_empty_lists(): + """API can return response.profile=None (e.g. new user); must not raise AttributeError.""" + + class FakeProfile: + static = ["fact"] + dynamic = ["recent"] + + class FakeResponse: + profile = None + search_results = None + + response = FakeResponse() + + # Mirrors the fixed logic in service.py _retrieve_memories() + profile_static = response.profile.static if response.profile is not None else [] + profile_dynamic = response.profile.dynamic if response.profile is not None else [] + + assert profile_static == [] + assert profile_dynamic == [] + + # Also verify non-None profile still works correctly + response.profile = FakeProfile() + profile_static = response.profile.static if response.profile is not None else [] + profile_dynamic = response.profile.dynamic if response.profile is not None else [] + + assert profile_static == ["fact"] + assert profile_dynamic == ["recent"]