Skip to content

[BUG]SQLServer数据源偶发保存失败 #1358

Description

@lumx316

保存数据源时,测试链接成功,保存时偶发失败。
报错提示:'sessionmaker' object has no attribute 'close'

版本社区版 V1.10.1

报错日志:
AttributeError: 'sessionmaker' object has no attribute 'close' ERROR: Exception in ASGI application

  • Exception Group Traceback (most recent call last):
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 76, in collapse_excgroups
    | yield
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 177, in call
    | async with anyio.create_task_group() as task_group:
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 815, in aexit
    | raise BaseExceptionGroup(
    | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
    +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 422, in run_asgi
    | result = await app( # type: ignore[func-returns-value]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 63, in call
    | return await self.app(scope, receive, send)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in call
    | await super().call(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/applications.py", line 112, in call
    | await self.middleware_stack(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in call
    | raise exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in call
    | await self.app(scope, receive, _send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call
    | with recv_stream, send_stream, collapse_excgroups():
    | File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit
    | self.gen.throw(typ, value, traceback)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    | raise exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call
    | response = await self.dispatch_func(request, call_next)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/common/audit/schemas/request_context.py", line 34, in dispatch
    | response = await call_next(request)
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next
    | raise app_exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    | await self.app(scope, receive_or_disconnect, send_no_error)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call
    | with recv_stream, send_stream, collapse_excgroups():
    | File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit
    | self.gen.throw(typ, value, traceback)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    | raise exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call
    | response = await self.dispatch_func(request, call_next)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/apps/system/schemas/permission.py", line 135, in dispatch
    | response = await call_next(request)
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next
    | raise app_exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    | await self.app(scope, receive_or_disconnect, send_no_error)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call
    | with recv_stream, send_stream, collapse_excgroups():
    | File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit
    | self.gen.throw(typ, value, traceback)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    | raise exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call
    | response = await self.dispatch_func(request, call_next)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/common/core/response_middleware.py", line 28, in dispatch
    | response = await call_next(request)
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next
    | raise app_exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    | await self.app(scope, receive_or_disconnect, send_no_error)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call
    | with recv_stream, send_stream, collapse_excgroups():
    | File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit
    | self.gen.throw(typ, value, traceback)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    | raise exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call
    | response = await self.dispatch_func(request, call_next)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/apps/system/middleware/auth.py", line 88, in dispatch
    | return await call_next(request)
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next
    | raise app_exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro
    | await self.app(scope, receive_or_disconnect, send_no_error)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 93, in call
    | await self.simple_response(scope, receive, send, request_headers=headers)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 144, in simple_response
    | await self.app(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in call
    | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    | raise exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    | await app(scope, receive, sender)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 714, in call
    | await self.middleware_stack(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 734, in app
    | await route.handle(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle
    | await self.app(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
    | await wrap_app_handling_exceptions(app, request)(scope, receive, send)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    | raise exc
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    | await app(scope, receive, sender)
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 73, in app
    | response = await f(request)
    | ^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 301, in app
    | raw_response = await run_endpoint_function(
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    | return await dependant.call(**values)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/apps/system/schemas/permission.py", line 101, in wrapper
    | return await func(args, *kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/common/audit/schemas/logger_decorator.py", line 591, in async_wrapper
    | raise e
    | File "/opt/sqlbot/app/common/audit/schemas/logger_decorator.py", line 569, in async_wrapper
    | result = await func(args, *kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/apps/datasource/api/datasource.py", line 102, in update
    | return await asyncio.to_thread(inner)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/usr/local/lib/python3.11/asyncio/threads.py", line 25, in to_thread
    | return await loop.run_in_executor(None, func_call)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    | result = self.fn(self.args, *self.kwargs)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/apps/datasource/api/datasource.py", line 100, in inner
    | return update_ds(session, trans, user, ds)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/opt/sqlbot/app/apps/datasource/crud/datasource.py", line 114, in update_ds
    | pool_manager.remove_pool(ds.id)
    | File "/opt/sqlbot/app/apps/db/db.py", line 1192, in remove_pool
    | pool.close()
    | ^^^^^^^^^^
    | AttributeError: 'sessionmaker' object has no attribute 'close'
    +------------------------------------
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last): File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 422, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 63, in call return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in call await super().call(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/applications.py", line 112, in call await self.middleware_stack(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in call raise exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in call await self.app(scope, receive, _send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call with recv_stream, send_stream, collapse_excgroups(): File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups raise exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call response = await self.dispatch_func(request, call_next) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/common/audit/schemas/request_context.py", line 34, in dispatch response = await call_next(request) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next raise app_exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call with recv_stream, send_stream, collapse_excgroups(): File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups raise exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call response = await self.dispatch_func(request, call_next) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/apps/system/schemas/permission.py", line 135, in dispatch response = await call_next(request) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next raise app_exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call with recv_stream, send_stream, collapse_excgroups(): File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups raise exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call response = await self.dispatch_func(request, call_next) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/common/core/response_middleware.py", line 28, in dispatch response = await call_next(request) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next raise app_exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 176, in call with recv_stream, send_stream, collapse_excgroups(): File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit self.gen.throw(typ, value, traceback) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups raise exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 178, in call response = await self.dispatch_func(request, call_next) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/apps/system/middleware/auth.py", line 88, in dispatch return await call_next(request) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 156, in call_next raise app_exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 141, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 93, in call await self.simple_response(scope, receive, send, request_headers=headers) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 144, in simple_response await self.app(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in call await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 714, in call await self.middleware_stack(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 734, in app await route.handle(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle await self.app(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 76, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app raise exc File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app await app(scope, receive, sender) File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 73, in app response = await f(request) ^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 301, in app raw_response = await run_endpoint_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 212, in run_endpoint_function return await dependant.call(values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/apps/system/schemas/permission.py", line 101, in wrapper return await func(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/common/audit/schemas/logger_decorator.py", line 591, in async_wrapper raise e File "/opt/sqlbot/app/common/audit/schemas/logger_decorator.py", line 569, in async_wrapper result = await func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/apps/datasource/api/datasource.py", line 102, in update return await asyncio.to_thread(inner) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/threads.py", line 25, in to_thread return await loop.run_in_executor(None, func_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/apps/datasource/api/datasource.py", line 100, in inner return update_ds(session, trans, user, ds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/sqlbot/app/apps/datasource/crud/datasource.py", line 114, in update_ds pool_manager.remove_pool(ds.id) File "/opt/sqlbot/app/apps/db/db.py", line 1192, in remove_pool pool.close() ^^^^^^^^^^ AttributeError: 'sessionmaker' object has no attribute 'close'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions