MountainDash / nonebot-bison

A nonebot2 plugin to repost social media posts to QQ group
https://nonebot-bison.netlify.app
MIT License
166 stars 35 forks source link

使用nb-cli安装插件后启动报错 #240

Closed UKMeng closed 1 year ago

UKMeng commented 1 year ago

环境

问题

在正常运行的项目基础上加装bison插件,启动失败,删除插件后又正常运行。考虑到可能是插件之间可能存在冲突问题,所以新建了一个项目单独安装插件,仍然报相同的错误。

麻烦开发大大们帮忙看看,非常感谢

复现问题步骤

  1. 使用nb-cli创建一个项目(bootstrap,驱动器FastAPI,适配器OneBot V11,安装依赖,创建虚拟环境)
  2. 进入虚拟环境,安装插件
    nb plugin install nonebot-bison
  3. nb run运行,然后报错退出,日志如下

日志

使用 Python: /Users/ukm/Developer/Python/NoneBot/bisontest/.venv/bin/python
04-19 13:38:15 [SUCCESS] nonebot | NoneBot is initializing...
04-19 13:38:15 [INFO] nonebot | Current Env: prod
04-19 13:38:15 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
04-19 13:38:15 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_apscheduler"
04-19 13:38:15 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_localstore"
04-19 13:38:18 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_datastore"
04-19 13:38:21 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_htmlrender"
04-19 13:38:21 [INFO] nonebot_bison | Nonebot test frontend will be running at: http://localhost:8080/bison
04-19 13:38:21 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_bison"
04-19 13:38:21 [SUCCESS] nonebot | Running NoneBot...
04-19 13:38:23 [INFO] logging | Started server process [35220]
04-19 13:38:23 [INFO] logging | Waiting for application startup.
04-19 13:38:23 [INFO] nonebot_plugin_apscheduler | Scheduler Started
04-19 13:38:24 [ERROR] logging | Traceback (most recent call last):
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/starlette/routing.py", line 677, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/Users/ukm/.pyenv/versions/3.11.3/lib/python3.11/contextlib.py", line 204, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot/drivers/fastapi.py", line 165, in _lifespan_manager
    await self._lifespan.startup()
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot/drivers/_lifespan.py", line 35, in startup
    await self._run_lifespan_func(self._startup_funcs)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot/drivers/_lifespan.py", line 29, in _run_lifespan_func
    await cast(ASYNC_LIFESPAN_FUNC, func)()
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/db.py", line 86, in init_db
    await run_upgrade()
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/utils.py", line 121, in run_upgrade
    await upgrade(config, "head")
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/command.py", line 245, in upgrade
    await run_migration()
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/utils.py", line 109, in run_migration
    await connection.run_sync(do_run_migrations, plugin_name)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/engine.py", line 787, in run_sync
    return await greenlet_spawn(fn, self._proxied, *arg, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 167, in greenlet_spawn
    result = context.switch(value)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/utils.py", line 101, in do_run_migrations
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/alembic/runtime/environment.py", line 868, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 622, in run_migrations
    step.migration_fn(**kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_bison/config/migrations/bd92923c218f_alter_json_not_null.py", line 38, in upgrade
    set_default_value()
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_bison/config/migrations/bd92923c218f_alter_json_not_null.py", line 23, in set_default_value
    Base.prepare(autoload_with=op.get_bind())
  File "<string>", line 2, in prepare
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 277, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/ext/automap.py", line 1230, in prepare
    cls.metadata.reflect(autoload_with, **opts)  # type: ignore[arg-type]  # noqa: E501
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 5553, in reflect
    Table(name, self, **reflect_opts)
  File "<string>", line 2, in __new__
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 277, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 428, in __new__
    return cls._new(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 482, in _new
    with util.safe_reraise():
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 478, in _new
    table.__init__(name, metadata, *args, _no_init=False, **kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 854, in __init__
    self._autoload(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 886, in _autoload
    conn_insp.reflect_table(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 1579, in reflect_table
    self._reflect_fk(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 1780, in _reflect_fk
    sa_schema.Table(
  File "<string>", line 2, in __new__
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 277, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 428, in __new__
    return cls._new(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 482, in _new
    with util.safe_reraise():
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 478, in _new
    table.__init__(name, metadata, *args, _no_init=False, **kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 854, in __init__
    self._autoload(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 886, in _autoload
    conn_insp.reflect_table(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 1547, in reflect_table
    raise exc.NoSuchTableError(table_name)
sqlalchemy.exc.NoSuchTableError: target

04-19 13:38:24 [ERROR] logging | Application startup failed. Exiting.
he0119 commented 1 year ago

能否运行 nb datastore history 后,将输出发上来呢?

UKMeng commented 1 year ago

感谢回复,这是运行nb datastore history的输出

04-20 09:07:04 [SUCCESS] nonebot | NoneBot is initializing...
04-20 09:07:04 [INFO] nonebot | Current Env: prod
04-20 09:07:04 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
04-20 09:07:04 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_apscheduler"
04-20 09:07:04 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_localstore"
04-20 09:07:05 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_datastore"
04-20 09:07:05 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_htmlrender"
04-20 09:07:05 [INFO] nonebot_bison | Nonebot test frontend will be running at: http://localhost:8080/bison
04-20 09:07:05 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_bison"
<string>:20: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
04-20 09:07:05 [INFO] nonebot_plugin_datastore | 查看插件 nonebot_bison 的数据库历史
bd92923c218f -> aceef470d69c (head), alter fields not null
5da28f6facb3 -> bd92923c218f, alter_json_not_null
5f3370328e44 -> 5da28f6facb3, rename tables
a333d6224193 -> 5f3370328e44, add time-weight table
4a46ba54a3f3 -> a333d6224193, add last scheduled time
c97c445e2bdb -> 4a46ba54a3f3, alter type
0571870f5222 -> c97c445e2bdb, add constraint
<base> -> 0571870f5222, init db
he0119 commented 1 year ago

感觉没啥问题啊,再试试 nb datastore history -i 呢?这个是可以查看当前的 revision。

最后你可以试试 nb datastore downgrade base 然后再 nb datastore upgrade,看看是不是还是一样报错。相当于重新来一遍。

UKMeng commented 1 year ago

这是nb datastore history -i的输出

04-20 09:35:27 [SUCCESS] nonebot | NoneBot is initializing...
04-20 09:35:27 [INFO] nonebot | Current Env: prod
04-20 09:35:28 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
04-20 09:35:28 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_apscheduler"
04-20 09:35:28 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_localstore"
04-20 09:35:29 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_datastore"
04-20 09:35:30 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_htmlrender"
04-20 09:35:30 [INFO] nonebot_bison | Nonebot test frontend will be running at: http://localhost:8080/bison
04-20 09:35:30 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_bison"
<string>:20: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
04-20 09:35:31 [INFO] nonebot_plugin_datastore | 查看插件 nonebot_bison 的数据库历史
bd92923c218f -> aceef470d69c (head), alter fields not null
5da28f6facb3 -> bd92923c218f, alter_json_not_null
5f3370328e44 -> 5da28f6facb3 (current), rename tables
a333d6224193 -> 5f3370328e44, add time-weight table
4a46ba54a3f3 -> a333d6224193, add last scheduled time
c97c445e2bdb -> 4a46ba54a3f3, alter type
0571870f5222 -> c97c445e2bdb, add constraint
<base> -> 0571870f5222, init db

在执行nb datastore upgrade这一步的时候就报错了

使用 Python: /Users/ukm/Developer/Python/NoneBot/bisontest/.venv/bin/python
04-20 09:36:53 [SUCCESS] nonebot | NoneBot is initializing...
04-20 09:36:53 [INFO] nonebot | Current Env: prod
04-20 09:36:53 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
04-20 09:36:53 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_apscheduler"
04-20 09:36:53 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_localstore"
04-20 09:36:53 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_datastore"
04-20 09:36:54 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_htmlrender"
04-20 09:36:54 [INFO] nonebot_bison | Nonebot test frontend will be running at: http://localhost:8080/bison
04-20 09:36:54 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_bison"
<string>:20: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
04-20 09:36:54 [INFO] nonebot_plugin_datastore | 升级插件 nonebot_bison 的数据库
Traceback (most recent call last):
  File "<string>", line 26, in <module>
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/cli.py", line 204, in main
    anyio.run(run_sync(cli))  # pragma: no cover
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/_core/_eventloop.py", line 70, in run
    return asynclib.run(func, *args, **backend_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 292, in run
    return native_run(wrapper(), debug=debug)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/.pyenv/versions/3.11.3/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/ukm/.pyenv/versions/3.11.3/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/.pyenv/versions/3.11.3/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 287, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/cli.py", line 30, in wrapper
    return await anyio.to_thread.run_sync(partial(func, *args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/cli.py", line 38, in wrapper
    return anyio.from_thread.run(partial(func, *args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/from_thread.py", line 49, in run
    return asynclib.run_async_from_thread(func, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 970, in run_async_from_thread
    return f.result()
           ^^^^^^^^^^
  File "/Users/ukm/.pyenv/versions/3.11.3/lib/python3.11/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/.pyenv/versions/3.11.3/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/cli.py", line 105, in upgrade
    await command.upgrade(config, revision)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/command.py", line 245, in upgrade
    await run_migration()
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/utils.py", line 109, in run_migration
    await connection.run_sync(do_run_migrations, plugin_name)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/engine.py", line 787, in run_sync
    return await greenlet_spawn(fn, self._proxied, *arg, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 167, in greenlet_spawn
    result = context.switch(value)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_plugin_datastore/script/utils.py", line 101, in do_run_migrations
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/alembic/runtime/environment.py", line 868, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 622, in run_migrations
    step.migration_fn(**kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_bison/config/migrations/bd92923c218f_alter_json_not_null.py", line 38, in upgrade
    set_default_value()
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/nonebot_bison/config/migrations/bd92923c218f_alter_json_not_null.py", line 23, in set_default_value
    Base.prepare(autoload_with=op.get_bind())
  File "<string>", line 2, in prepare
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 277, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/ext/automap.py", line 1230, in prepare
    cls.metadata.reflect(autoload_with, **opts)  # type: ignore[arg-type]  # noqa: E501
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 5553, in reflect
    Table(name, self, **reflect_opts)
  File "<string>", line 2, in __new__
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 277, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 428, in __new__
    return cls._new(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 482, in _new
    with util.safe_reraise():
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 478, in _new
    table.__init__(name, metadata, *args, _no_init=False, **kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 854, in __init__
    self._autoload(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 886, in _autoload
    conn_insp.reflect_table(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 1579, in reflect_table
    self._reflect_fk(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 1780, in _reflect_fk
    sa_schema.Table(
  File "<string>", line 2, in __new__
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 277, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 428, in __new__
    return cls._new(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 482, in _new
    with util.safe_reraise():
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 478, in _new
    table.__init__(name, metadata, *args, _no_init=False, **kw)
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 854, in __init__
    self._autoload(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 886, in _autoload
    conn_insp.reflect_table(
  File "/Users/ukm/Developer/Python/NoneBot/bisontest/.venv/lib/python3.11/site-packages/sqlalchemy/engine/reflection.py", line 1547, in reflect_table
    raise exc.NoSuchTableError(table_name)
sqlalchemy.exc.NoSuchTableError: target
he0119 commented 1 year ago

看来需要看看数据库内部的情况了,你方便看看现在数据库内有什么表吗?DB Browser for SQLite 这个软件就可以。

UKMeng commented 1 year ago

我在新建的项目找不到任何数据库文件,会不会是这个原因。在我原本运行的项目里的data文件夹则是有

|-- data
    |-- data.sqlite3
    |-- data.sqlite3-shm
    |-- data.sqlite3-wal
    |-- 其他插件的数据文件夹(略)
he0119 commented 1 year ago

不会,因为 datastore 的数据库存放位置比较标准(使用官方插件 localstore 提供的位置)。你可以通过 nb datastore dir 查看。对了,在数据目录下的 data.db。

UKMeng commented 1 year ago

久等了 这是data.db的表的情况

image
he0119 commented 1 year ago

久等了 这是data.db的表的情况 image

所以 target 哪来的 ){(2~Z VH S WHWB%WM%Q_E

我这边没法复现,太怪了。要不来群里慢慢聊?

UKMeng commented 1 year ago

我把data.db移走,重新运行了一次nb run,生成的还是这5张表

image

请务必拉我进群81e13eb4017ab525a033d5c80eebbd22

he0119 commented 1 year ago

README 上就有的。https://qm.qq.com/cgi-bin/qm/qr?k=pXYMGB_e8b6so3QTqgeV6lkKDtEeYE4f&jump_from=webapi

he0119 commented 1 year ago

话说是加不进来吗?如果不行就加这个吧 https://jq.qq.com/?_wv=1027&k=7zQUpiGp

he0119 commented 1 year ago

经过一些操作发现,问题出在 5da28f6facb3_rename_tables 迁移脚本。

执行后 Referrences 并没有改变:

}MJWYUFY1_SNYL`VC)4W2$O

正常情况如下:

QWA4L4YT9H4KFTYEK~S2@9Y

但我还是没法复现,不清楚具体原因。

he0119 commented 1 year ago

经过进一步排查,并直接运行以下脚本发现,问题出在 sqlite 上。

import sqlite3

print(sqlite3.version)
print(sqlite3.sqlite_version)

con = sqlite3.connect("data.db")
cur = con.cursor()
cur.execute("ALTER TABLE target RENAME TO nonebot_bison_target")
cur.execute("ALTER TABLE user RENAME TO nonebot_bison_user")
cur.execute(
    "ALTER TABLE schedule_time_weight RENAME TO nonebot_bison_scheduletimeweight"
)
cur.execute("ALTER TABLE subscribe RENAME TO nonebot_bison_subscribe")
UKMeng commented 1 year ago

sqlite3.sqlite_version=3.39.5时修改表名reference会出现不更改的问题 sqlite3.sqlite_version=3.41.0时不会出现这个问题