Skip to content

适配pydantic v2 #419

@YuYue-Amatsuki

Description

@YuYue-Amatsuki

如以下报错所示,本插件与使用pydantic v2的其他插件不兼容,启动时则报错

10-06 10:53:56 [ERROR] nonebot | Failed to import "nonebot_plugin_mystool"
Traceback (most recent call last):
  File "C:\Users\YuYue\Desktop\yuyue_bot\bot.py", line 29, in <module>
    nonebot.load_from_toml("pyproject.toml")
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\plugin\load.py", line 133, in load_from_toml
    return load_all_plugins(plugins, plugin_dirs)
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\plugin\load.py", line 67, in load_all_plugins
    return manager.load_all_plugins()
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\plugin\manager.py", line 205, in load_all_plugins
    return set(
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\plugin\manager.py", line 206, in <genexpr>
    filter(None, (self.load_plugin(name) for name in self.available_plugins))
> File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\plugin\manager.py", line 169, in load_plugin
    module = importlib.import_module(self._third_party_plugin_ids[name])
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot\plugin\manager.py", line 257, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_mystool\__init__.py", line 43, in <module>
    from .model.upgrade import upgrade_plugin_data
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_mystool\model\__init__.py", line 1, in <modu
le>
    from .common import *
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\nonebot_plugin_mystool\model\common.py", line 488, in <modu
le>
    class BaseApiStatus(BaseModel):
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\pydantic\_internal\_model_construction.py", line 112, in __
new__
    private_attributes = inspect_namespace(
  File "C:\Users\YuYue\AppData\Local\Programs\Python\Python310\lib\site-packages\pydantic\_internal\_model_construction.py", line 459, in in
spect_namespace
    raise PydanticUserError(
pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `success = False`. All model fields require a type annotation; if
 `success` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ign
ored_types']`.

For further information visit https://errors.pydantic.dev/2.11/u/model-field-missing-annotation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions