Hyperion
Hyperion copied to clipboard
Subscribing to topic ph raise a postgresql error
Exception in ASGI application Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 538, in _prepare_and_execute self._rows = deque(await prepared_stmt.fetch(*parameters)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/asyncpg/prepared_[stmt.py](http://stmt.py/)", line 176, in fetch data = await self.__bind_execute(args, 0, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/asyncpg/prepared_[stmt.py](http://stmt.py/)", line 241, in __bind_execute data, status, _ = await self.__do_execute( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/asyncpg/prepared_[stmt.py](http://stmt.py/)", line 230, in __do_execute return await executor(protocol) ^^^^^^^^^^^^^^^^^^^^^^^^ File "asyncpg/protocol/protocol.pyx", line 207, in bind_execute asyncpg.exceptions.InvalidTextRepresentationError: invalid input value for enum topic: "ph" The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[base.py](http://base.py/)", line 1967, in _exec_single_context [self.dialect.do](http://self.dialect.do/)_execute( File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[default.py](http://default.py/)", line 941, in do_execute cursor.execute(statement, parameters) File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 572, in execute self._adapt_connection.await_( File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_[py3k.py](http://py3k.py/)", line 132, in await_only return current.parent.switch(awaitable) # type: ignore[no-any-return,attr-defined] # noqa: E501 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_[py3k.py](http://py3k.py/)", line 196, in greenlet_spawn value = await result ^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 550, in _prepare_and_execute self._handle_exception(error) File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 501, in _handle_exception self._adapt_connection._handle_exception(error) File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 784, in _handle_exception raise translated_error from error sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_asyncpg_dbapi.Error: : invalid input value for enum topic: "ph" The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_[impl.py](http://impl.py/)", line 401, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_[headers.py](http://headers.py/)", line 70, in __call__ return await [self.app](http://self.app/)(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/fastapi/[applications.py](http://applications.py/)", line 1054, in __call__ await super().__call__(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/[applications.py](http://applications.py/)", line 123, in __call__ await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[errors.py](http://errors.py/)", line 186, in __call__ raise exc File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[errors.py](http://errors.py/)", line 164, in __call__ await [self.app](http://self.app/)(scope, receive, _send) File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[base.py](http://base.py/)", line 189, in __call__ with collapse_excgroups(): File "/usr/local/lib/python3.11/[contextlib.py](http://contextlib.py/)", line 158, in __exit__ self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.11/site-packages/starlette/_[utils.py](http://utils.py/)", line 93, in collapse_excgroups raise exc File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[base.py](http://base.py/)", line 191, in __call__ response = await self.dispatch_func(request, call_next) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/app/[app.py](http://app.py/)", line 414, in logging_middleware response = await call_next(request) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[base.py](http://base.py/)", line 165, in call_next raise app_exc File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[base.py](http://base.py/)", line 151, in coro await [self.app](http://self.app/)(scope, receive_or_disconnect, send_no_error) File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[cors.py](http://cors.py/)", line 93, in __call__ await self.simple_response(scope, receive, send, request_headers=headers) File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[cors.py](http://cors.py/)", line 148, in simple_response await [self.app](http://self.app/)(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/middleware/[exceptions.py](http://exceptions.py/)", line 65, in __call__ await wrap_app_handling_exceptions([self.app](http://self.app/), conn)(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/_exception_[handler.py](http://handler.py/)", line 64, in wrapped_app raise exc File "/usr/local/lib/python3.11/site-packages/starlette/_exception_[handler.py](http://handler.py/)", line 53, in wrapped_app await app(scope, receive, sender) File "/usr/local/lib/python3.11/site-packages/starlette/[routing.py](http://routing.py/)", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/[routing.py](http://routing.py/)", line 776, in app await route.handle(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/[routing.py](http://routing.py/)", line 297, in handle await [self.app](http://self.app/)(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/[routing.py](http://routing.py/)", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/usr/local/lib/python3.11/site-packages/starlette/_exception_[handler.py](http://handler.py/)", line 64, in wrapped_app raise exc File "/usr/local/lib/python3.11/site-packages/starlette/_exception_[handler.py](http://handler.py/)", line 53, in wrapped_app await app(scope, receive, sender) File "/usr/local/lib/python3.11/site-packages/starlette/[routing.py](http://routing.py/)", line 72, in app response = await func(request) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/fastapi/[routing.py](http://routing.py/)", line 278, in app raw_response = await run_endpoint_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/fastapi/[routing.py](http://routing.py/)", line 191, in run_endpoint_function return await [dependant.call](http://dependant.call/)(**values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/app/core/notification/endpoints_[notification.py](http://notification.py/)", line 166, in subscribe_to_topic await notification_manager.subscribe_user_to_topic( File "/app/app/utils/communication/[notifications.py](http://notifications.py/)", line 250, in subscribe_user_to_topic await cruds_notification.get_topic_membership_by_user_id_and_custom_topic( File "/app/app/core/notification/cruds_[notification.py](http://notification.py/)", line 275, in get_topic_membership_by_user_id_and_custom_topic result = await db.execute( ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/[session.py](http://session.py/)", line 461, in execute result = await greenlet_spawn( ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_[py3k.py](http://py3k.py/)", line 201, in greenlet_spawn result = context.throw(*sys.exc_info()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/[session.py](http://session.py/)", line 2362, in execute return self._execute_internal( ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/[session.py](http://session.py/)", line 2247, in _execute_internal result: Result[Any] = compile_state_cls.orm_execute_statement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/[context.py](http://context.py/)", line 293, in orm_execute_statement result = conn.execute( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[base.py](http://base.py/)", line 1418, in execute return meth( ^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/[elements.py](http://elements.py/)", line 515, in _execute_on_connection return connection._execute_clauseelement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[base.py](http://base.py/)", line 1640, in _execute_clauseelement ret = self._execute_context( ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[base.py](http://base.py/)", line 1846, in _execute_context return self._exec_single_context( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[base.py](http://base.py/)", line 1986, in _exec_single_context self._handle_dbapi_exception( File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[base.py](http://base.py/)", line 2355, in _handle_dbapi_exception raise sqlalchemy_exception.with_traceback(exc_info[2]) from e File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[base.py](http://base.py/)", line 1967, in _exec_single_context [self.dialect.do](http://self.dialect.do/)_execute( File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/[default.py](http://default.py/)", line 941, in do_execute cursor.execute(statement, parameters) File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 572, in execute self._adapt_connection.await_( File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_[py3k.py](http://py3k.py/)", line 132, in await_only return current.parent.switch(awaitable) # type: ignore[no-any-return,attr-defined] # noqa: E501 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_[py3k.py](http://py3k.py/)", line 196, in greenlet_spawn value = await result ^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 550, in _prepare_and_execute self._handle_exception(error) File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 501, in _handle_exception self._adapt_connection._handle_exception(error) File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/[asyncpg.py](http://asyncpg.py/)", line 784, in _handle_exception raise translated_error from error sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) : invalid input value for enum topic: "ph" [SQL: SELECT notification_topic_membership.user_id, notification_topic_membership.topic, notification_topic_membership.topic_identifier FROM notification_topic_membership WHERE notification_topic_membership.user_id = $1::VARCHAR AND notification_topic_membership.topic = $2::topic AND notification_topic_membership.topic_identifier = $3::VARCHAR] [parameters: ('5e5a3d4a-57cb-4c27-8ed5-1b507140779c', 'ph', '')] (Background on this error at: https://sqlalche.me/e/20/dbapi)
At the very end, exactly before throwing the SQL command:
invalid input value for enum topic: "ph"
The db confirms this when you ask it directly (using Postgres):
# select enum_range(null::topic);
enum_range
------------------------------------------------------------------
{cinema,advert,bookingadmin,amap,booking,event,loan,raffle,vote}
(1 row)
This shows two things:
- Good news: it's exclusively a problem in migrations (the rest is OK, the search area becomes smaller)
- Bad news: this issue is broader than expected (beyond the ph), because that enum single-handedly proves at least two migrations went wrong:
-
13-ph.py: there is noph -
11-Remove_bookingadmin_topic.py: there is stillbookingadmin
-
Hopefully #680 will fix this case by recreating this enum and the notification_topic_membership table