From 165e8a4d938e50fc8ca59355a373d761df210317 Mon Sep 17 00:00:00 2001 From: Aegis Dev Date: Sun, 31 May 2026 18:35:54 -0400 Subject: [PATCH] fix(pipecat): guard against None profile in _retrieve_memories() response.profile can be None when the API returns no data for a new user, causing an AttributeError. Added None checks before accessing .static and .dynamic, returning empty lists in that case. Fixes #1027 --- .../src/supermemory_pipecat/service.py | 7 ++-- .../tests/test_service_none_profile.py | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 packages/pipecat-sdk-python/tests/test_service_none_profile.py 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"]