Skip to content

fix: use .get() for user_review to prevent KeyError - #4500

Merged
beastoin merged 2 commits into
mainfrom
fix/memories-user-review-keyerror-4498
Feb 1, 2026
Merged

beastoin merged 2 commits into
mainfrom
fix/memories-user-review-keyerror-4498

Conversation

@beastoin

@beastoin beastoin commented Feb 1, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4498

Changed memory['user_review'] to memory.get('user_review') in backend/database/memories.py:94 to prevent KeyError when memory documents are missing the user_review field. The .get() method returns None for missing keys, which correctly passes the is not False check, preserving the original behavior of including all memories except those explicitly marked False. Added regression tests covering missing field, None, True, False, and mixed values.

deploy:


by AI for @beastoin

Memory documents may be missing the user_review field, causing KeyError
when filtering memories in get_memories(). Using .get() returns None
for missing keys, which correctly passes the `is not False` check.

Fixes #4498

Co-Authored-By: Claude Opus 4.5 <[email protected]>
gemini-code-assist[bot]

This comment was marked as resolved.

@beastoin

beastoin commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator Author

@beastoin The fix looks right, but please add a regression test for get_memories covering a document missing user_review and one with user_review=False to prevent the 500 and keep the filter behavior stable (backend/database/memories.py:94). Can you add that test (or point me to existing coverage)?


by AI for @beastoin

Tests verify the user_review filtering logic in get_memories():
- Missing field -> included (None is not False)
- user_review=None -> included
- user_review=True -> included
- user_review=False -> excluded
- Verifies old behavior would KeyError

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@beastoin

beastoin commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator Author

Added regression tests in backend/tests/unit/test_memories_user_review.py:

  • test_memory_without_user_review_field_included - verifies missing field doesn't crash
  • test_memory_with_user_review_none_included - None is included
  • test_memory_with_user_review_false_excluded - False is excluded
  • test_memory_with_user_review_true_included - True is included
  • test_mixed_user_review_values - combined test
  • test_old_behavior_would_keyerror - confirms the bug existed

All tests pass locally (backend/test.sh). Ready for re-review.

@beastoin

beastoin commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator Author

@beastoin The .get() change addresses the KeyError and the new unit tests cover missing/None/False/True cases plus mixed values; I didn't run backend/test.sh locally in this environment. Please merge when ready.


by AI for @beastoin

@beastoin

beastoin commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator Author

lgtm @beastoin

@beastoin
beastoin merged commit 74a4ece into main Feb 1, 2026
1 check passed
@beastoin
beastoin deleted the fix/memories-user-review-keyerror-4498 branch February 1, 2026 09:11
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
Fixes BasedHardware#4498

Changed `memory['user_review']` to `memory.get('user_review')` in
`backend/database/memories.py:94` to prevent KeyError when memory
documents are missing the `user_review` field. The `.get()` method
returns `None` for missing keys, which correctly passes the `is not
False` check, preserving the original behavior of including all memories
except those explicitly marked `False`. Added regression tests covering
missing field, None, True, False, and mixed values.

**deploy:**
- [ ] deploy backend

---
_by AI for @beastoin_
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.

GET /v3/memories returns 500 when memory record missing 'user_review' field

1 participant