Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解析配置项 "application_commands": {"*": ["*"]} 时抛出 TypeError #16

Closed
Autuamn opened this issue Mar 6, 2024 · 1 comment
Closed

Comments

@Autuamn
Copy link
Contributor

Autuamn commented Mar 6, 2024

版本

  • nonebot2 2.2.1
  • nonebot-adapter-discord 0.1.4
  • pydantic 2.6.3
  • pydantic_core 2.16.3

log

Traceback (most recent call last):
  File "<string>", line 17, in <module>
  File ".venv\Lib\site-packages\nonebot\internal\driver\abstract.py", line 79, in register_adapter
    self._adapters[name] = adapter(self, **kwargs)
                           ^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\nonebot\adapters\discord\adapter.py", line 43, in __init__
    self.discord_config: Config = get_plugin_config(Config)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\nonebot\plugin\__init__.py", line 120, in get_plugin_config
    return type_validate_python(config, model_dump(get_driver().config))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\nonebot\compat.py", line 215, in type_validate_python
    return TypeAdapter(type_).validate_python(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\pydantic\type_adapter.py", line 256, in validate_python
    return self.validator.validate_python(__object, strict=strict, from_attributes=from_attributes, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\nonebot\adapters\discord\api\model.py", line 113, in validate
    raise TypeError(f"{value!r} is not int or str of int")
TypeError: '*' is not int or str of int

尝试

  • .env 里删去 application_commands
  • 写成 "application_commands": {"*": [123]}

以上两种情况不会报错,只要 [] 里包含 "*" 就会报错


application_commands: Dict[str, List[Union[Snowflake, Literal["*"]]]] = Field(
default_factory=dict
)

尝试把此处的 Union 写成 Union[Literal["*"], Snowflake] 就不会报错

🤔十分神奇,请求支援

@CMHopeSunshine
Copy link
Member

应该是pydantic v1和v2的union机制不同,方便开个pr调整一下union顺序吗

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

No branches or pull requests

2 participants