fix(vector_stores): return None from Redis.get() for missing IDs (#5625)
Co-authored-by: ly-wang19 <ly-wang19@users.noreply.github.com> Co-authored-by: Kartik <kartik.labhshetwar@mem0.ai>
This commit is contained in:
co-authored by
ly-wang19
Kartik
parent
ff53fd60b7
commit
c5971193a2
@@ -113,3 +113,18 @@ def test_list_with_filter_builds_query():
|
||||
|
||||
query = mock_index.search.call_args[0][0]
|
||||
assert query.query_string() == "@user_id:{alice}"
|
||||
|
||||
|
||||
def test_get_returns_none_for_missing_id():
|
||||
"""get() must return None for a missing id.
|
||||
|
||||
redisvl's SearchIndex.fetch() returns None when the id is not found, so the
|
||||
old code raised ``TypeError: 'NoneType' object is not subscriptable`` on
|
||||
``result["hash"]``. Every other vector store returns None for a missing id,
|
||||
and Memory relies on it (``if existing_memory is None``), so get() must too.
|
||||
"""
|
||||
db, mock_index = _make_redis_db()
|
||||
mock_index.fetch.return_value = None
|
||||
|
||||
assert db.get("missing_id") is None
|
||||
mock_index.fetch.assert_called_once_with("missing_id")
|
||||
|
||||
Reference in New Issue
Block a user