Akashdeep Dhar | The database session handling (or the way I am doing it) seems flawed.
[W2FM] [2024-08-02 10:33:51 +0530] [ERROR] Exception in ASGI application
Traceback (most recent call last):
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 399, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/routing.py", line 756, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/routing.py", line 776, in app
await route.handle(scope, receive, send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/routing.py", line 72, in app
response = await func(request)
^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/fastapi/routing.py", line 278, in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/fastapi/routing.py", line 193, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 859, in run
result = context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/archdesk/Projects/webhook-to-fedora-messaging/webhook_to_fedora_messaging/endpoints/user.py", line 46, in create_user
session.flush()
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4341, in flush
self._flush(objects)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4433, in _flush
flush_context.transaction = transaction = self._autobegin_t()._begin()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 2, in _begin
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 103, in _go
self._raise_for_prerequisite_state(fn.__name__, current_state)
File "/home/archdesk/Projects/webhook-to-fedora-messaging/venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 973, in _raise_for_prerequisite_state
raise sa_exc.PendingRollbackError(
sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "uq_users_username"
DETAIL: Key (username)=(string) already exists.
[SQL: INSERT INTO users (username, is_admin, uuid, creation_date) VALUES (%(username)s, %(is_admin)s, %(uuid)s, %(creation_date)s) RETURNING users.id]
[parameters: {'username': 'string', 'is_admin': False, 'uuid': '2108d717', 'creation_date': datetime.datetime(2024, 8, 2, 5, 3, 41, 509271)}]
(Background on this error at: https://sqlalche.me/e/20/gkpj) (Background on this error at: https://sqlalche.me/e/20/7s2a)
| 05:05:14 |