NapNeko / NapCatQQ

现代化的基于 NTQQ 的 Bot 协议端实现
https://napcat.napneko.icu
Other
2.71k stars 197 forks source link

[BUG] 私聊情况下输入状态会出现pydantic.error_wrappers.ValidationError错误 #234

Closed DreamGallery closed 3 months ago

DreamGallery commented 3 months ago

系统版本

Debian12

QQNT 版本

Linux 3.2.12-26702

NapCat 版本

1.8.6

OneBot 客户端

Nonebot2.3.2

发生了什么?

私聊机器人的情况下会出现validation_error,群聊并不会。

如何复现

只要私聊输入就会在nonebot日志中报错两次

期望的结果?

大概是输入状态造成引发的错误,私聊也并没有group_id这个属性吧?

NapCat 运行日志

NapCat日志没有报错,一切正常

OneBot 客户端运行日志

客户端日志如下

08-09 18:44:25 [DEBUG] nonebot | OneBot V11 | Event Parser Error
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/__init__.py", line 335, in run
    get_driver().run(*args, **kwargs)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 186, in run
    uvicorn.run(
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/main.py", line 577, in run
    server.run()
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 373, in handle
    await self.app(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 96, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 94, in app
    await func(session)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/fastapi/routing.py", line 348, in app
    await dependant.call(**values)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 143, in _handle
    await self._handle_ws(websocket, setup)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 252, in _handle_ws
    await setup.handle_func(ws)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/adapters/onebot/v11/adapter.py", line 248, in _handle_ws
    if event := self.json_to_event(json_data):
> File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/adapters/onebot/v11/adapter.py", line 431, in json_to_event
    event = type_validate_python(model, json_data)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/compat.py", line 372, in type_validate_python
    return parse_obj_as(type_, data)
  File "pydantic/tools.py", line 38, in pydantic.tools.parse_obj_as
    return model_type(__root__=obj).__root__
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for ParsingModel[NotifyEvent]
__root__ -> group_id
  field required (type=value_error.missing)
08-09 18:44:25 [SUCCESS] nonebot | OneBot V11 xxxxxxxxxx | [notice.notify.input_status]: {'time': 1723229065, 'self_id': xxxxxxxxxx, 'post_type': 'notice', 'notice_type': 'notify', 'user_id': xxxxxxxxx, 'status_text': '', 'sub_type': 'input_status', 'event_type': 2}
08-09 18:44:25 [DEBUG] nonebot | Checking for matchers in priority 0...
08-09 18:44:25 [DEBUG] nonebot | Checking for matchers in priority 1...
08-09 18:44:25 [DEBUG] nonebot | Checking for matchers in priority 5...
08-09 18:44:25 [DEBUG] nonebot | Checking for matchers in priority 12...
08-09 18:44:25 [DEBUG] nonebot | Checking for matchers in priority 99...
08-09 18:44:25 [DEBUG] nonebot | Checking for matchers completed
08-09 18:44:25 [DEBUG] nonebot | Running PostProcessors...
08-09 18:44:26 [DEBUG] nonebot | OneBot V11 | Event Parser Error
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/__init__.py", line 335, in run
    get_driver().run(*args, **kwargs)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 186, in run
    uvicorn.run(
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/main.py", line 577, in run
    server.run()
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 373, in handle
    await self.app(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 96, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/starlette/routing.py", line 94, in app
    await func(session)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/fastapi/routing.py", line 348, in app
    await dependant.call(**values)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 143, in _handle
    await self._handle_ws(websocket, setup)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/drivers/fastapi.py", line 252, in _handle_ws
    await setup.handle_func(ws)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/adapters/onebot/v11/adapter.py", line 248, in _handle_ws
    if event := self.json_to_event(json_data):
> File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/adapters/onebot/v11/adapter.py", line 431, in json_to_event
    event = type_validate_python(model, json_data)
  File "/home/nonebot/miniconda3/envs/campus/lib/python3.12/site-packages/nonebot/compat.py", line 372, in type_validate_python
    return parse_obj_as(type_, data)
  File "pydantic/tools.py", line 38, in pydantic.tools.parse_obj_as
    return model_type(__root__=obj).__root__
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for ParsingModel[NotifyEvent]
__root__ -> group_id
  field required (type=value_error.missing)
MliKiowa commented 3 months ago

扩展事件有待考虑

DreamGallery commented 3 months ago

V2.0.6版本中已经修复了这个报错,大佬们辛苦了