mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

Fix: openmemory get memories crash

Open jomenxiao opened this issue 6 months ago • 3 comments

Description

  1. insert one or two memory to openmemory(frist starting)
curl -X 'POST' \
  'http://192.168.1.16:8765/api/v1/memories/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "user_id": "root",
  "text": "test",
  "metadata": {},
  "infer": true,
  "app": "openmemory"
}'
  1. fetch memory and crash
(base) ➜  ~ curl -X 'GET' \
  'http://192.168.1.16:8765/api/v1/memories/?user_id=root&page=1&size=50' \
  -H 'accept: application/json'
Internal Server Error%
  1. output
openmemory-mcp-1  | /usr/local/lib/python3.12/site-packages/pydantic/_internal/_config.py:323: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.11/migration/
openmemory-mcp-1  |   warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)
openmemory-mcp-1  | /usr/src/openmemory/app/schemas.py:53: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.11/migration/
openmemory-mcp-1  |   @validator('created_at', pre=True)
openmemory-mcp-1  | INFO:     Started server process [9]
openmemory-mcp-1  | INFO:     Waiting for application startup.
openmemory-mcp-1  | INFO:     Application startup complete.
openmemory-mcp-1  | /usr/src/openmemory/app/routers/memories.py:155: DeprecationWarning: sqlalchemy.orm.Query is deprecated, use sqlalchemy.sql.Select instead sqlalchemy.orm.Query support will be removed in the next major release (0.13.0).
openmemory-mcp-1  |   paginated_results = sqlalchemy_paginate(query, params)
openmemory-mcp-1  | INFO:     192.168.1.43:54579 - "GET /api/v1/memories/?user_id=root&page=1&size=50 HTTP/1.1" 500 Internal Server Error
openmemory-mcp-1  | ERROR:    Exception in ASGI application
openmemory-mcp-1  | Traceback (most recent call last):
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
openmemory-mcp-1  |     result = await app(  # type: ignore[func-returns-value]
openmemory-mcp-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
openmemory-mcp-1  |     return await self.app(scope, receive, send)
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
openmemory-mcp-1  |     await super().__call__(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/applications.py", line 112, in __call__
openmemory-mcp-1  |     await self.middleware_stack(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in __call__
openmemory-mcp-1  |     raise exc
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in __call__
openmemory-mcp-1  |     await self.app(scope, receive, _send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in __call__
openmemory-mcp-1  |     await self.app(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
openmemory-mcp-1  |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
openmemory-mcp-1  |     raise exc
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
openmemory-mcp-1  |     await app(scope, receive, sender)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 714, in __call__
openmemory-mcp-1  |     await self.middleware_stack(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 734, in app
openmemory-mcp-1  |     await route.handle(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle
openmemory-mcp-1  |     await self.app(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 76, in app
openmemory-mcp-1  |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
openmemory-mcp-1  |     raise exc
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
openmemory-mcp-1  |     await app(scope, receive, sender)
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 73, in app
openmemory-mcp-1  |     response = await f(request)
openmemory-mcp-1  |                ^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi/routing.py", line 301, in app
openmemory-mcp-1  |     raw_response = await run_endpoint_function(
openmemory-mcp-1  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
openmemory-mcp-1  |     return await dependant.call(**values)
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/src/openmemory/app/routers/memories.py", line 155, in list_memories
openmemory-mcp-1  |     paginated_results = sqlalchemy_paginate(query, params)
openmemory-mcp-1  |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/ext/sqlalchemy.py", line 451, in paginate
openmemory-mcp-1  |     return run_sync_flow(
openmemory-mcp-1  |            ^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/flow.py", line 56, in run_sync_flow
openmemory-mcp-1  |     res = gen.throw(exc)
openmemory-mcp-1  |           ^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/flow.py", line 51, in run_sync_flow
openmemory-mcp-1  |     res = gen.send(res)
openmemory-mcp-1  |           ^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/ext/sqlalchemy.py", line 323, in _sqlalchemy_flow
openmemory-mcp-1  |     page = yield from generic_flow(
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/flows.py", line 136, in generic_flow
openmemory-mcp-1  |     page = yield from create_page_flow(
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/flows.py", line 72, in create_page_flow
openmemory-mcp-1  |     page = yield create_page_factory(
openmemory-mcp-1  |                  ^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/api.py", line 102, in create_page
openmemory-mcp-1  |     return resolve_page(params).create(items, **kwargs)
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/default.py", line 63, in create
openmemory-mcp-1  |     return create_pydantic_model(
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/fastapi_pagination/utils.py", line 185, in create_pydantic_model
openmemory-mcp-1  |     return model_cls.model_validate(kwargs, from_attributes=True)
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  |   File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 703, in model_validate
openmemory-mcp-1  |     return cls.__pydantic_validator__.validate_python(
openmemory-mcp-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openmemory-mcp-1  | pydantic_core._pydantic_core.ValidationError: 4 validation errors for Page[MemoryResponse]
openmemory-mcp-1  | items.0.app_name
openmemory-mcp-1  |   Field required [type=missing, input_value=<app.models.Memory object at 0x7f39ffe13950>, input_type=Memory]
openmemory-mcp-1  |     For further information visit https://errors.pydantic.dev/2.11/v/missing
openmemory-mcp-1  | items.1.app_name
openmemory-mcp-1  |   Field required [type=missing, input_value=<app.models.Memory object at 0x7f39ffe13920>, input_type=Memory]
openmemory-mcp-1  |     For further information visit https://errors.pydantic.dev/2.11/v/missing
openmemory-mcp-1  | items.2.app_name
openmemory-mcp-1  |   Field required [type=missing, input_value=<app.models.Memory object at 0x7f39ffe138f0>, input_type=Memory]
openmemory-mcp-1  |     For further information visit https://errors.pydantic.dev/2.11/v/missing
openmemory-mcp-1  | items.3.app_name
openmemory-mcp-1  |   Field required [type=missing, input_value=<app.models.Memory object at 0x7f39ffe139e0>, input_type=Memory]
openmemory-mcp-1  |     For further information visit https://errors.pydantic.dev/2.11/v/missing
(base) ➜  curl -X 'GET' \
  'http://192.168.1.16:8765/api/v1/memories/?user_id=root&page=1&size=50' \
  -H 'accept: application/json'
{"items":[{"id":"c95d3d22-1ca0-4eca-abdd-a0dbf64d07a3","content":"asdfasdfasdfasdfasdf","created_at":1747219776,"state":"active","app_id":"f38b2650-44c6-4da4-9a3c-1aaa0b778dac","app_name":"openmemory","categories":[],"metadata_":{}},{"id":"a9db6e3e-9ec3-469d-aa7c-723a1c65240b","content":"asdfasdfasdfasdfasdf","created_at":1747224206,"state":"active","app_id":"f38b2650-44c6-4da4-9a3c-1aaa0b778dac","app_name":"openmemory","categories":[],"metadata_":{}},{"id":"bf8ecefb-3e6c-42dc-9318-4bd316f8a06b","content":"asdfasdfasdfasdfasdfasdfsafsadfasdfasdfasfasdfasfasdfasdf","created_at":1747380529,"state":"active","app_id":"f38b2650-44c6-4da4-9a3c-1aaa0b778dac","app_name":"openmemory","categories":[],"metadata_":{}}],"total":3,"page":1,"size":50,"pages":1}%

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Please delete options that are not relevant.

  • [X] Unit Test

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
  • [X] I have made corresponding changes to the documentation
  • [X] My changes generate no new warnings
  • [X] I have added tests that prove my fix is effective or that my feature works
  • [X] New and existing unit tests pass locally with my changes
  • [X] 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

jomenxiao avatar May 16 '25 08:05 jomenxiao

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 16 '25 08:05 CLAassistant

Hi @jomenxiao, could you please elaborate on the exact issue this addresses and how we might reproduce it?

whysosaket avatar May 16 '25 16:05 whysosaket

Hi @jomenxiao, could you please elaborate on the exact issue this addresses and how we might reproduce it?

miss, and reedit it https://github.com/mem0ai/mem0/pull/2701#issue-3068336883

jomenxiao avatar May 17 '25 10:05 jomenxiao