Skip to content

fix: raise ValueError when deleting nonexistent memory#4455

Merged
kartik-mem0 merged 2 commits intomainfrom
fix/3849-delete-memory-null-check
Mar 20, 2026
Merged

fix: raise ValueError when deleting nonexistent memory#4455
kartik-mem0 merged 2 commits intomainfrom
fix/3849-delete-memory-null-check

Conversation

@kartik-mem0
Copy link
Copy Markdown
Contributor

@kartik-mem0 kartik-mem0 commented Mar 20, 2026

Description

When vector_store.get() returns None (memory ID not found), the code accesses .payload on None, causing an unhelpful AttributeError: 'NoneType' object has no attribute 'payload'.

This affects delete(), update(), and the session ID update handler in add() — all 3 code paths hit the same crash. Confirmed that all 6 vector store implementations (Qdrant, MongoDB, PGVector,
FAISS, Pinecone, Supabase) can return None from get().

This fix adds null checks after every vector_store.get() call that accesses .payload in both Memory and AsyncMemory:

  • _delete_memory() — raises ValueError with descriptive message
  • _update_memory() — raises ValueError with descriptive message
  • add() NONE event handler — logs warning and skips gracefully

Fixes #3849

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test

Added 4 new tests:

  • test_delete_nonexistent_memory_raises_error — verifies sync delete() raises ValueError when memory ID doesn't exist, and does not call vector_store.delete()
  • test_async_delete_nonexistent_memory_raises_error — verifies the same for AsyncMemory.delete()
  • test_update_nonexistent_memory_raises_error — verifies sync _update_memory() raises ValueError when memory ID doesn't exist, and does not call vector_store.update()
  • test_async_update_nonexistent_memory_raises_error — verifies the same for AsyncMemory._update_memory()

pytest tests/test_memory.py -v

21/21 passed

Bug reproduction verified — without the fix, both delete() and update() crash with AttributeError: 'NoneType' object has no attribute 'payload'. With the fix, they raise a clear ValueError.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Maintainer Checklist

@kartik-mem0 kartik-mem0 merged commit 2b95583 into main Mar 20, 2026
8 checks passed
@kartik-mem0 kartik-mem0 deleted the fix/3849-delete-memory-null-check branch March 20, 2026 12:59
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

# Bug Report: memory.delete() fails with AttributeError: 'NoneType' object has no attribute 'payload' when using Qdrant

2 participants