sqlalchemy.orm.exc.DetachedInstanceError #775
Unanswered
ChengChe106
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! I've encountered a problem that I can't resolve. I'm hoping for some help! Thank you in advance for your reply!
When I click the edit button, it works correctly.
But if I click View buttom. it raises an error.
**ERROR: Exception in ASGI application
Traceback (most recent call last):
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 426, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in call
return await self.app(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\fastapi\applications.py", line 1054, in call
await super().call(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\applications.py", line 116, in call
await self.middleware_stack(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\middleware\exceptions.py", line 62, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette_exception_handler.py", line 55, in wrapped_app
raise exc
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette_exception_handler.py", line 44, in wrapped_app
await app(scope, receive, sender)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\routing.py", line 746, in call
await route.handle(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\routing.py", line 459, in handle
await self.app(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\applications.py", line 116, in call
await self.middleware_stack(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\middleware\sessions.py", line 83, in call
await self.app(scope, receive, send_wrapper)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\middleware\exceptions.py", line 62, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette_exception_handler.py", line 55, in wrapped_app
raise exc
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette_exception_handler.py", line 44, in wrapped_app
await app(scope, receive, sender)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\routing.py", line 746, in call
await route.handle(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\routing.py", line 288, in handle
await self.app(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\routing.py", line 75, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette_exception_handler.py", line 55, in wrapped_app
raise exc
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette_exception_handler.py", line 44, in wrapped_app
await app(scope, receive, sender)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\starlette\routing.py", line 70, in app
response = await func(request)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\authentication.py", line 66, in wrapper_decorator
return await func(*args, kwargs)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\application.py", line 466, in details
return await self.templates.TemplateResponse(
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\templating.py", line 63, in TemplateResponse
content = await template.render_async(context)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\jinja2\environment.py", line 1324, in render_async
return self.environment.handle_exception()
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\jinja2\environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\jinja2\environment.py", line 1321, in
[n async for n in self.root_render_func(ctx)] # type: ignore
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\templates\details.html", line 1, in top-level template code
{% extends "layout.html" %}
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\templates\layout.html", line 2, in top-level template code
{% from 'macros.html' import display_menu %}
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\templates\base.html", line 18, in top-level template code
{% block body %}
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\templates\layout.html", line 49, in block 'body'
{% block content %} {% endblock %}
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqladmin\templates\details.html", line 31, in block 'content'
({{ formatted_elem }})
File "F:\Python310\lib\dataclasses.py", line 239, in wrapper
result = user_function(self)
File "", line 3, in repr
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 566, in get
return self.impl.get(state, dict) # type: ignore[no-any-return]
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 1086, in get
value = self._fire_loader_callables(state, key, passive)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 1121, in fire_loader_callables
return self.callable(state, passive)
File "F:\PythonProjects\FastAPI\FastAPISystem\venv\lib\site-packages\sqlalchemy\orm\strategies.py", line 918, in _load_for_state
raise orm_exc.DetachedInstanceError(
sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <PermissionGroup at 0x28da6ca69b0> is not bound to a Session; lazy load operation of attribute 'users' cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)
here is some my code.
src/admin/admin.py
src/auth/model.py
Beta Was this translation helpful? Give feedback.
All reactions