mem0
mem0 copied to clipboard
Fix: use correct paginator for filtered memory list in /api/v1/memories/endpoint
Fix /api/v1/memories/ endpoint to use correct pagination for filtered lists
- Switch from
sqlalchemy_paginatetopaginatefor/api/v1/memories/GET endpoint - Ensure results are filtered and serialized before pagination
- Prevents internal server error when filtering with Python logic
Description
This change updates the /api/v1/memories/ endpoint to use the correct pagination function when filtering results in Python. Previously, the endpoint used sqlalchemy_paginate, which expects a SQLAlchemy query object, but after filtering with a Python function, the result was a list. Passing a list to sqlalchemy_paginate caused internal server errors.
Now, the endpoint uses the standard paginate function from fastapi_pagination, which is designed to work with lists. The results are filtered and serialized to the MemoryResponse Pydantic model before pagination, ensuring the response matches the expected schema and eliminating the server error.
Motivation:
To fix a bug that caused a 500 Internal Server Error when accessing /api/v1/memories/ with filters that require Python-side logic.
Dependencies:
No new dependencies are required for this change.
Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Refactor (does not change functionality, e.g. code style improvements, linting)
- [ ] Documentation update
How Has This Been Tested?
- [x] Manual testing: Accessed
/api/v1/memories/?user_id=bulkypandaand verified that the endpoint returns paginated results without error. - [x] Confirmed that filtering and pagination work as expected.
Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] 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
- [ ] Any dependent changes have been merged and published in downstream modules
- [x] I have checked my code and corrected any misspellings
Maintainer Checklist
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] Made sure Checks passed