Giter Site home page Giter Site logo

fastapi-user-auth-demo's People

Contributors

amisadmin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fastapi-user-auth-demo's Issues

使用postgresql启动报错,sql语句错误,fastapi_amis_admin_nav库引起

当前版本:
dependencies = [
"uvicorn>=0.18.3",
"pydantic[dotenv]>=2.0.0",
"pydantic-settings>=2.1.0",
"aiosqlite>=0.15.0",
"fastapi-user-auth<0.8.0,>=0.7.0",
"fastapi-amis-admin-nav<0.2.0,>=0.1.3",
"fastapi-scheduler<0.1.0,>=0.0.15",
"sqlmodelx>=0.0.9",
"alembic>=1.7.6",
]
经过多次验证,sqlite不会报错,但使用postgresql启动报错,报错原因为类型不匹配:
详细错误如下:
Traceback (most recent call last):
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\starlette\routing.py", line 677, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\starlette\routing.py", line 566, in aenter
await self._router.startup()
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\starlette\routing.py", line 654, in startup
await handler()
File "D:\code\github\fastapi-user-auth-demo.\backend\main.py", line 47, in startup
await site.router.startup()
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\starlette\routing.py", line 654, in startup
await handler()
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\fastapi_amis_admin_nav\admin.py", line 80, in sync_pages
await self.site.db.async_run_sync(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy_database\database.py", line 193, in run_sync
return await self.session.run_sync(fn, *args, **kwargs)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\ext\asyncio\session.py", line 389, in run_sync
return await greenlet_spawn(fn, self.sync_session, *arg, **kw)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 192, in greenlet_spawn
result = context.switch(value)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\fastapi_amis_admin_nav\admin.py", line 81, in
lambda session: AmisPageManager(session).site_to_db(self.site).db_to_site(self.site)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\fastapi_amis_admin_nav\utils.py", line 70, in site_to_db
parent_id = append_page_to_db(admin_group)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\fastapi_amis_admin_nav\utils.py", line 65, in append_page_to_db
self.session.flush() # 刷新,获取page_id
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\orm\session.py", line 4312, in flush
self._flush(objects)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\orm\session.py", line 4447, in _flush
with util.safe_reraise():
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in exit
raise exc_value.with_traceback(exc_tb)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\orm\session.py", line 4408, in _flush
flush_context.execute()
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 466, in execute
rec.execute(self)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 642, in execute
util.preloaded.orm_persistence.save_obj(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\orm\persistence.py", line 93, in save_obj
_emit_insert_statements(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\orm\persistence.py", line 1226, in _emit_insert_statements
result = connection.execute(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1416, in execute
return meth(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\sql\elements.py", line 516, in _execute_on_connection
return connection._execute_clauseelement(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1639, in _execute_clauseelement
ret = self._execute_context(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1848, in _execute_context
return self._exec_single_context(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1988, in _exec_single_context
self._handle_dbapi_exception(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\engine\base.py", line 2343, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\engine\base.py", line 1969, in _exec_single_context
self.dialect.do_execute(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\engine\default.py", line 922, in do_execute
cursor.execute(statement, parameters)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 591, in execute
self.adapt_connection.await(
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 125, in await_only
return current.driver.switch(awaitable) # type: ignore[no-any-return]
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 185, in greenlet_spawn
value = await result
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 569, in _prepare_and_execute
self._handle_exception(error)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 520, in _handle_exception
self._adapt_connection._handle_exception(error)
File "d:\code\github\fastapi-user-auth-demo.venv\lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 808, in _handle_exception
raise translated_error from error
sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.DataError'>: invalid input for query argument $1: 6 (expected str, got int)
[SQL: INSERT INTO system_page (type, url, label, icon, sort, "desc", page_schema, parent_id, unique_id, "tabsMode", visible, is_group, is_custom, is_active, is_locked, update_time) VALUES ($1::VARCHAR, $2::VARCHAR, $3::VARCHAR, $4::VARCHAR, $5::INTEGER, $6::VARCHAR, $7::VARCHAR, $8::INTEGER, $9::VARCHAR, $10::tabsmodeenum, $11::BOOLEAN, $12::BOOLEAN, $13::BOOLEAN, $14::BOOLEAN, $15::BOOLEAN, $16::TIMESTAMP WITHOUT TIME ZONE) RETURNING system_page.id]
[parameters: (6, '/admin/', 'FastAPI-Amis-Admin', 'https://baidu.gitee.io/amis/static/favicon_b3b0647.png', 0, '', '{"label":"FastAPI-Amis-Admin","icon":"https://baidu.gitee.io/amis/static/favicon_b3b0647.png","url":"/admin/"}', None, 'AuthAdminSite', None, True, True, False, True, False, datetime.datetime(2023, 12, 28, 22, 40, 20, 849744))]
(Background on this error at: https://sqlalche.me/e/20/dbapi)

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

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的问题吗?

项目依赖资源失效

克隆项目原样启动, 打开首页得:

image

<Error>
  <Code>AccessDenied</Code>
  <Message>You have no right to access this object because of bucket acl.</Message>
  <RequestId>62D123E5D6E8C8313799AAF2</RequestId>
  <HostId>fe-static-zbprod-zb1-oss-3.oss-cn-zhangjiakou.aliyuncs.com</HostId>
</Error>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.