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

Bug: 插件在运行期间创建的 Matcher 没有 plugin_name 属性 #1843

Closed
MeetWq opened this issue Mar 25, 2023 · 3 comments · Fixed by #1857
Closed

Bug: 插件在运行期间创建的 Matcher 没有 plugin_name 属性 #1843

MeetWq opened this issue Mar 25, 2023 · 3 comments · Fixed by #1857
Labels
bug Something isn't working

Comments

@MeetWq
Copy link
Contributor

MeetWq commented Mar 25, 2023

描述问题:

插件若在 nonebot 启动后再动态创建 Matcher,这些 Matcher 的 plugin_name 属性为 None,而很多管理类插件需要用到 matcher.plugin_name

如何复现?

在 nonebot 启动后创建 Matcher,如在 on_startup 中创建 Matcher

示例:nonebot-plugin-memes-api 插件在 on_startup 中创建 Matcher: code

有些 bot 直接使用 matcher.plugin_name,导致如下的报错:
-797b4f1fd0a37362

期望的结果

由于 nonebot 中 Matcher 的 plugin_name 属性为 Optional,不确定这一结果是否是预期行为?

如果是,有没有好的办法在动态创建 Matcher 时定义 plugin_name 呢?

@MeetWq MeetWq added the bug Something isn't working label Mar 25, 2023
@yanyongyu
Copy link
Member

yanyongyu commented Mar 26, 2023

plugin相关属性目前只有在插件导入时可以进行跟踪,但是module属性应该是有的,可以考虑通过module寻找plugin

@yanyongyu
Copy link
Member

这边遇到了一个小问题,运行时插件新建的matcher是否应该添加到plugin.matcher存储里

@yanyongyu
Copy link
Member

目前做法是仅加载期间的响应器会被添加到插件对象存储里,为了防止运行时内存泄露

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants