amisadmin/fastapi-user-auth-demo

demo最新版启动时遇到“sqlite3.OperationalError: database is locked”错误

weihuan opened this issue · 1 comments

demo当前更新后,发现启动后@app.on_event("startup")执行到“ await site.router.startup() ”时出错,错误信息如下

ERROR:    Traceback (most recent call last):
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\dialects\sqlite\aiosqlite.py", line 100, in execute
    self._adapt_connection._handle_exception(error)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\dialects\sqlite\aiosqlite.py", line 228, in _handle_exception
    raise error
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\dialects\sqlite\aiosqlite.py", line 82, in execute
    self.await_(_cursor.execute(operation, parameters))
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 68, in await_only
    return current.driver.switch(awaitable)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 121, in greenlet_spawn
    value = await result
            ^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\cursor.py", line 48, in execute
    await self._execute(self._cursor.execute, sql, parameters)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\cursor.py", line 40, in _execute
    return await self._conn._execute(fn, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\core.py", line 133, in _execute
    return await future
           ^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\core.py", line 106, in run
    result = function()
             ^^^^^^^^^^
sqlite3.OperationalError: database is locked

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\starlette\routing.py", line 677, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\starlette\routing.py", line 566, in __aenter__
    await self._router.startup()
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\starlette\routing.py", line 654, in startup
    await handler()
  File "C:\WebProjects\my_experiments\backend\main.py", line 50, in startup
    await site.router.startup()
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\starlette\routing.py", line 654, in startup
    await handler()
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\fastapi_user_auth\admin\admin.py", line 387, in _load_policy
    await self.load_policy()
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\fastapi_user_auth\admin\admin.py", line 392, in load_policy
    await update_casbin_site_grouping(self.site.auth.enforcer, self.site)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\fastapi_user_auth\admin\utils.py", line 102, in update_casbin_site_grouping
    await enforcer.add_named_grouping_policies("g2", add_roles)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\casbin\async_management_enforcer.py", line 249, in add_named_grouping_policies
    rules_added = await self._add_policies("g", ptype, rules)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\casbin\async_internal_enforcer.py", line 143, in _add_policies
    result = await self.adapter.add_policies(sec, ptype, rules)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\fastapi_user_auth\utils\sqlachemy_adapter.py", line 153, in add_policies
    await self.db.async_execute(insert(self._db_class).values(values))
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\ext\asyncio\session.py", line 215, in execute
    result = await greenlet_spawn(
             ^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 126, in greenlet_spawn
    result = context.throw(*sys.exc_info())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlmodel\orm\session.py", line 101, in execute
    return super().execute(  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\orm\session.py", line 1712, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 1705, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\sql\elements.py", line 333, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 1572, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 1943, in _execute_context
    self._handle_dbapi_exception(
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 2124, in _handle_dbapi_exception
    util.raise_(
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\util\compat.py", line 208, in raise_
    raise exception
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\engine\default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\dialects\sqlite\aiosqlite.py", line 100, in execute
    self._adapt_connection._handle_exception(error)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\dialects\sqlite\aiosqlite.py", line 228, in _handle_exception
    raise error
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\dialects\sqlite\aiosqlite.py", line 82, in execute
    self.await_(_cursor.execute(operation, parameters))
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 68, in await_only
    return current.driver.switch(awaitable)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\sqlalchemy\util\_concurrency_py3k.py", line 121, in greenlet_spawn
    value = await result
            ^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\cursor.py", line 48, in execute
    await self._execute(self._cursor.execute, sql, parameters)
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\cursor.py", line 40, in _execute
    return await self._conn._execute(fn, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\core.py", line 133, in _execute
    return await future
           ^^^^^^^^^^^^
  File "c:\WebProjects\my_experiments\.venv\Lib\site-packages\aiosqlite\core.py", line 106, in run
    result = function()
             ^^^^^^^^^^
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked
[SQL: INSERT INTO auth_casbin_rule (id, ptype, v0, v1, v2, v3, v4, v5) VALUES (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: (None, 'g2', 'Auth>UserAuthApp', 'Auth>CasbinRuleAdmin', None, None, None, None, None, 'g2', 'Auth>UserAuthApp', 'Auth>LoginHistoryAdmin', None, None, None, None, None, 'g2', 'AuthAdminSite', '283002fe81d9bbae', None, None, None, None, None, 'g2', 'Auth>UserAuthApp', 'Auth>RoleAdmin', None, None, None, None, None, 'g2', 'Auth>UserAuthApp', 'Auth>UserLoginFormAdmin', None, None, None, None, None, 'g2', 'Auth>UserAuthApp', 'Auth>UserAdmin', None, None, None, None, None, 'g2', 'AuthAdminSite', 'Auth>UserAuthApp', None, None, None, None, None, 'g2', 'f736aeb720a47010', 'b19cc208ea4e2622', None, None, None, None, None, 'g2', 'Auth>UserAuthApp', 'Auth>UserRegFormAdmin', None, None, None, None, None, 'g2', 'AuthAdminSite', 'f736aeb720a47010', None, None, None, None, None, 'g2', 'Auth>UserAuthApp', 'Auth>UserInfoFormAdmin', None, None, None, None, None, 'g2', 'AuthAdminSite', 'a42c53cb3721761c', None, None, None, None, None, 'g2', 'AuthAdminSite', '0765cdf25a1f9548', None, None, None, None, None, 'g2', 'f736aeb720a47010', 'a5d1401d49a19d97', None, None, None, None)]
(Background on this error at: https://sqlalche.me/e/14/e3q8)

2023-09-21 09:38:08,163 INFO sqlalchemy.engine.Engine ROLLBACK
ERROR:    Application startup failed. Exiting.

这是sqlite的问题吗?

同问,
mysql也不行