mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-30 01:51:28 +00:00
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
This commit is contained in:
parent
53c971ac85
commit
165e8a4d93
2 changed files with 37 additions and 2 deletions
|
|
@ -150,10 +150,13 @@ class SupermemoryPipecatService(FrameProcessor):
|
|||
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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
Loading…
Add table
Reference in a new issue