fix(redis): use .get() for hash/created_at in insert() to handle entity payloads (#5709)
This commit is contained in:
@@ -180,3 +180,51 @@ def test_get_returns_none_for_missing_id():
|
||||
|
||||
assert db.get("missing_id") is None
|
||||
mock_index.fetch.assert_called_once_with("missing_id")
|
||||
|
||||
|
||||
def test_insert_entity_payload_without_hash_and_created_at():
|
||||
"""insert() must not crash on entity payloads that lack hash/created_at."""
|
||||
db, mock_index = _make_redis_db()
|
||||
|
||||
entity_payload = {
|
||||
"data": "OpenAI",
|
||||
"entity_type": "organization",
|
||||
"linked_memory_ids": ["mem-1"],
|
||||
"user_id": "test_user",
|
||||
}
|
||||
|
||||
db.insert(
|
||||
vectors=[[0.1, 0.2, 0.3]],
|
||||
payloads=[entity_payload],
|
||||
ids=["entity-1"],
|
||||
)
|
||||
|
||||
mock_index.load.assert_called_once()
|
||||
data = mock_index.load.call_args[0][0]
|
||||
assert data[0]["memory_id"] == "entity-1"
|
||||
assert data[0]["memory"] == "OpenAI"
|
||||
assert data[0]["hash"] == ""
|
||||
assert data[0]["created_at"] == 0
|
||||
|
||||
|
||||
def test_update_entity_payload_without_hash_and_timestamps():
|
||||
"""update() must not crash on entity payloads that lack hash/created_at/updated_at."""
|
||||
db, mock_index = _make_redis_db()
|
||||
|
||||
entity_payload = {
|
||||
"data": "OpenAI",
|
||||
"entity_type": "organization",
|
||||
"linked_memory_ids": ["mem-1"],
|
||||
"user_id": "test_user",
|
||||
}
|
||||
|
||||
db.update(vector_id="entity-1", vector=[0.1, 0.2, 0.3], payload=entity_payload)
|
||||
|
||||
mock_index.load.assert_called_once()
|
||||
call_kwargs = mock_index.load.call_args
|
||||
data_dict = call_kwargs[1]["data"][0] if "data" in call_kwargs[1] else call_kwargs[0][0][0]
|
||||
assert data_dict["memory_id"] == "entity-1"
|
||||
assert data_dict["memory"] == "OpenAI"
|
||||
assert data_dict["hash"] == ""
|
||||
assert data_dict["created_at"] == 0
|
||||
assert data_dict["updated_at"] == 0
|
||||
|
||||
Reference in New Issue
Block a user