Skip to content

Unable to start langflow without autologin on kubernetes w/ fresh Postgres DB due to "Could not remove default superuser" #9187

@srinathh

Description

@srinathh

Bug Description

I am trying to deploy on kubernetes with LANGFLOW_AUTO_LOGIN set to false and setting LANGFLOW_SUPERUSER and LANGFLOW_SUPERUSER_PASSWORD environment variables. It is being setup in a fresh remote postgres database.

Here is the full error log

 ERROR    2025-07-25 14:25:05 - ERROR    - main - main.py:263
                             Unhandled error during cleanup: Could
                             not remove default superuser.Traceback
                             (most recent call last):

                             RuntimeError: Could not remove default
                             superuser.

                             ╭─ Traceback (most recent call last) ─╮
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/main.py:133 in        │
                             │ lifespan                            │
                             │                                     │
                             │   130 │   │   │   start_time = asyn │
                             │   131 │   │   │                     │
                             │   132 │   │   │   logger.debug("Ini │
                             │ ❱ 133 │   │   │   await initialize_ │
                             │   134 │   │   │   logger.debug(f"Se │
                             │       start_time:.2f}s")            │
                             │   135 │   │   │                     │
                             │   136 │   │   │   current_time = as │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/services/utils.py:234 │
                             │  in initialize_services             │
                             │                                     │
                             │   231 │   │   raise ConnectionError │
                             │   232 │                             │
                             │   233 │   # Setup the superuser     │
                             │ ❱ 234 │   await initialize_database │
                             │   235 │   db_service = get_db_servi │
                             │   236 │   await db_service.initiali │
                             │   237 │   async with db_service.wit │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/services/database/uti │
                             │ ls.py:40 in initialize_database     │
                             │                                     │
                             │   37 │   │   logger.exception(msg)  │
                             │   38 │   │   raise RuntimeError(msg │
                             │   39 │   try:                       │
                             │ ❱ 40 │   │   await database_service │
                             │   41 │   except CommandError as exc │
                             │   42 │   │   # if "overlaps with ot │
                             │      identified by"                 │
                             │   43 │   │   # are not in the excep │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/services/database/ser │
                             │ vice.py:371 in run_migrations       │
                             │                                     │
                             │   368 │   │   │   except Exception: │
                             │   369 │   │   │   │   logger.debug( │
                             │   370 │   │   │   │   should_initia │
                             │ ❱ 371 │   │   await asyncio.to_thre │
                             │   372 │                             │
                             │   373 │   @staticmethod             │
                             │   374 │   def try_downgrade_upgrade │
                             │                                     │
                             │ /usr/local/lib/python3.12/asyncio/t │
                             │ hreads.py:25 in to_thread           │
                             │                                     │
                             │   22 │   loop = events.get_running_ │
                             │   23 │   ctx = contextvars.copy_con │
                             │   24 │   func_call = functools.part │
                             │ ❱ 25 │   return await loop.run_in_e │
                             │   26                                │
                             │                                     │
                             │ /usr/local/lib/python3.12/concurren │
                             │ t/futures/thread.py:58 in run       │
                             │                                     │
                             │    55 │   │   │   return            │
                             │    56 │   │                         │
                             │    57 │   │   try:                  │
                             │ ❱  58 │   │   │   result = self.fn( │
                             │    59 │   │   except BaseException  │
                             │    60 │   │   │   self.future.set_e │
                             │    61 │   │   │   # Break a referen │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/services/database/ser │
                             │ vice.py:324 in _run_migrations      │
                             │                                     │
                             │   321 │   │   # which is a buffer   │
                             │   322 │   │   # I don't want to out │
                             │   323 │   │   # subprocess.DEVNULL  │
                             │ ❱ 324 │   │   with self.alembic_log │
                             │   325 │   │   │   alembic_cfg = Con │
                             │   326 │   │   │   # alembic_cfg.att │
                             │   327 │   │   │   alembic_cfg.set_m │
                             │                                     │
                             │ /usr/local/lib/python3.12/pathlib.p │
                             │ y:1013 in open                      │
                             │                                     │
                             │   1010 │   │   """                  │
                             │   1011 │   │   if "b" not in mode:  │
                             │   1012 │   │   │   encoding = io.te │
                             │ ❱ 1013 │   │   return io.open(self, │
                             │   1014 │                            │
                             │   1015 │   def read_bytes(self):    │
                             │   1016 │   │   """                  │
                             ╰─────────────────────────────────────╯
                             OSError: [Errno 30] Read-only file
                             system:
                             '/app/.venv/lib/python3.12/site-package
                             s/langflow/alembic/alembic.log'

                             During handling of the above exception,
                             another exception occurred:

                             ╭─ Traceback (most recent call last) ─╮
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/base.py:1963 │
                             │  in _exec_single_context            │
                             │                                     │
                             │   1960 │   │   │   │   │   │   │    │
                             │   1961 │   │   │   │   │   │   │    │
                             │   1962 │   │   │   │   if not evt_h │
                             │ ❱ 1963 │   │   │   │   │   self.dia │
                             │   1964 │   │   │   │   │   │   curs │
                             │   1965 │   │   │   │   │   )        │
                             │   1966                              │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/default.py:9 │
                             │ 43 in do_execute                    │
                             │                                     │
                             │    940 │   │   cursor.executemany(s │
                             │    941 │                            │
                             │    942 │   def do_execute(self, cur │
                             │ ❱  943 │   │   cursor.execute(state │
                             │    944 │                            │
                             │    945 │   def do_execute_no_params │
                             │    946 │   │   cursor.execute(state │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/dialects/postgresql │
                             │ /psycopg.py:594 in execute          │
                             │                                     │
                             │   591 │   │   self._cursor._close() │
                             │   592 │                             │
                             │   593 │   def execute(self, query,  │
                             │ ❱ 594 │   │   result = self.await_( │
                             │   595 │   │   # sqlalchemy result i │
                             │   596 │   │   res = self._cursor.pg │
                             │   597                               │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/util/_concurrency_p │
                             │ y3k.py:132 in await_only            │
                             │                                     │
                             │   129 │   # a coroutine to run. Onc │
                             │   130 │   # switches back to this g │
                             │   131 │   # then returned to the ca │
                             │ ❱ 132 │   return current.parent.swi │
                             │       # noqa: E501                  │
                             │   133                               │
                             │   134                               │
                             │   135 def await_fallback(awaitable: │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/util/_concurrency_p │
                             │ y3k.py:196 in greenlet_spawn        │
                             │                                     │
                             │   193 │   │   try:                  │
                             │   194 │   │   │   # wait for a coro │
                             │   195 │   │   │   # result back to  │
                             │ ❱ 196 │   │   │   value = await res │
                             │   197 │   │   except BaseException: │
                             │   198 │   │   │   # this allows an  │
                             │   199 │   │   │   # the moderated g │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/psycopg/cursor_async.py:97 in  │
                             │ execute                             │
                             │                                     │
                             │    94 │   │   │   │   │   self._exe │
                             │    95 │   │   │   │   )             │
                             │    96 │   │   except e._NO_TRACEBAC │
                             │ ❱  97 │   │   │   raise ex.with_tra │
                             │    98 │   │   return self           │
                             │    99 │                             │
                             │   100 │   async def executemany(    │
                             ╰─────────────────────────────────────╯
                             UndefinedTable: relation "user" does
                             not exist
                             LINE 2: FROM "user"
                                          ^

                             The above exception was the direct
                             cause of the following exception:

                             ╭─ Traceback (most recent call last) ─╮
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/services/utils.py:117 │
                             │  in teardown_superuser              │
                             │                                     │
                             │   114 │   │   │   from langflow.ser │
                             │   115 │   │   │                     │
                             │   116 │   │   │   stmt = select(Use │
                             │ ❱ 117 │   │   │   user = (await ses │
                             │   118 │   │   │   # Check if super  │
                             │   119 │   │   │   # if it has logge │
                             │   120 │   │   │   if user and user. │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlmodel/ext/asyncio/session.p │
                             │ y:81 in exec                        │
                             │                                     │
                             │    78 │   │   else:                 │
                             │    79 │   │   │   execution_options │
                             │    80 │   │                         │
                             │ ❱  81 │   │   result = await greenl │
                             │    82 │   │   │   self.sync_session │
                             │    83 │   │   │   statement,        │
                             │    84 │   │   │   params=params,    │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/util/_concurrency_p │
                             │ y3k.py:201 in greenlet_spawn        │
                             │                                     │
                             │   198 │   │   │   # this allows an  │
                             │   199 │   │   │   # the moderated g │
                             │   200 │   │   │   # its expected fl │
                             │ ❱ 201 │   │   │   result = context. │
                             │   202 │   │   else:                 │
                             │   203 │   │   │   result = context. │
                             │   204                               │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlmodel/orm/session.py:66 in  │
                             │ exec                                │
                             │                                     │
                             │    63 │   │   _parent_execute_state │
                             │    64 │   │   _add_event: Optional[ │
                             │    65 │   ) -> Union[TupleResult[_T │
                             │ ❱  66 │   │   results = super().exe │
                             │    67 │   │   │   statement,        │
                             │    68 │   │   │   params=params,    │
                             │    69 │   │   │   execution_options │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/orm/session.py:2365 │
                             │  in execute                         │
                             │                                     │
                             │   2362 │   │                        │
                             │   2363 │   │                        │
                             │   2364 │   │   """                  │
                             │ ❱ 2365 │   │   return self._execute │
                             │   2366 │   │   │   statement,       │
                             │   2367 │   │   │   params,          │
                             │   2368 │   │   │   execution_option │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/orm/session.py:2251 │
                             │  in _execute_internal               │
                             │                                     │
                             │   2248 │   │   │   )                │
                             │   2249 │   │                        │
                             │   2250 │   │   if compile_state_cls │
                             │ ❱ 2251 │   │   │   result: Result[A │
                             │   2252 │   │   │   │   self,        │
                             │   2253 │   │   │   │   statement,   │
                             │   2254 │   │   │   │   params or {} │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/orm/context.py:306  │
                             │ in orm_execute_statement            │
                             │                                     │
                             │    303 │   │   bind_arguments,      │
                             │    304 │   │   conn,                │
                             │    305 │   ) -> Result:             │
                             │ ❱  306 │   │   result = conn.execut │
                             │    307 │   │   │   statement, param │
                             │    308 │   │   )                    │
                             │    309 │   │   return cls.orm_setup │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/base.py:1415 │
                             │  in execute                         │
                             │                                     │
                             │   1412 │   │   except AttributeErro │
                             │   1413 │   │   │   raise exc.Object │
                             │   1414 │   │   else:                │
                             │ ❱ 1415 │   │   │   return meth(     │
                             │   1416 │   │   │   │   self,        │
                             │   1417 │   │   │   │   distilled_pa │
                             │   1418 │   │   │   │   execution_op │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/sql/elements.py:523 │
                             │  in _execute_on_connection          │
                             │                                     │
                             │    520 │   │   if self.supports_exe │
                             │    521 │   │   │   if TYPE_CHECKING │
                             │    522 │   │   │   │   assert isins │
                             │ ❱  523 │   │   │   return connectio │
                             │    524 │   │   │   │   self, distil │
                             │    525 │   │   │   )                │
                             │    526 │   │   else:                │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/base.py:1637 │
                             │  in _execute_clauseelement          │
                             │                                     │
                             │   1634 │   │   │   schema_translate │
                             │   1635 │   │   │   linting=self.dia │
                             │   1636 │   │   )                    │
                             │ ❱ 1637 │   │   ret = self._execute_ │
                             │   1638 │   │   │   dialect,         │
                             │   1639 │   │   │   dialect.executio │
                             │   1640 │   │   │   compiled_sql,    │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/base.py:1842 │
                             │  in _execute_context                │
                             │                                     │
                             │   1839 │   │   if context.execute_s │
                             │   1840 │   │   │   return self._exe │
                             │   1841 │   │   else:                │
                             │ ❱ 1842 │   │   │   return self._exe │
                             │   1843 │   │   │   │   dialect, con │
                             │   1844 │   │   │   )                │
                             │   1845                              │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/base.py:1982 │
                             │  in _exec_single_context            │
                             │                                     │
                             │   1979 │   │   │   result = context │
                             │   1980 │   │                        │
                             │   1981 │   │   except BaseException │
                             │ ❱ 1982 │   │   │   self._handle_dba │
                             │   1983 │   │   │   │   e, str_state │
                             │   1984 │   │   │   )                │
                             │   1985                              │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/base.py:2351 │
                             │  in _handle_dbapi_exception         │
                             │                                     │
                             │   2348 │   │   │   │   raise newrai │
                             │   2349 │   │   │   elif should_wrap │
                             │   2350 │   │   │   │   assert sqlal │
                             │ ❱ 2351 │   │   │   │   raise sqlalc │
                             │   2352 │   │   │   else:            │
                             │   2353 │   │   │   │   assert exc_i │
                             │   2354 │   │   │   │   raise exc_in │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/base.py:1963 │
                             │  in _exec_single_context            │
                             │                                     │
                             │   1960 │   │   │   │   │   │   │    │
                             │   1961 │   │   │   │   │   │   │    │
                             │   1962 │   │   │   │   if not evt_h │
                             │ ❱ 1963 │   │   │   │   │   self.dia │
                             │   1964 │   │   │   │   │   │   curs │
                             │   1965 │   │   │   │   │   )        │
                             │   1966                              │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/engine/default.py:9 │
                             │ 43 in do_execute                    │
                             │                                     │
                             │    940 │   │   cursor.executemany(s │
                             │    941 │                            │
                             │    942 │   def do_execute(self, cur │
                             │ ❱  943 │   │   cursor.execute(state │
                             │    944 │                            │
                             │    945 │   def do_execute_no_params │
                             │    946 │   │   cursor.execute(state │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/dialects/postgresql │
                             │ /psycopg.py:594 in execute          │
                             │                                     │
                             │   591 │   │   self._cursor._close() │
                             │   592 │                             │
                             │   593 │   def execute(self, query,  │
                             │ ❱ 594 │   │   result = self.await_( │
                             │   595 │   │   # sqlalchemy result i │
                             │   596 │   │   res = self._cursor.pg │
                             │   597                               │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/util/_concurrency_p │
                             │ y3k.py:132 in await_only            │
                             │                                     │
                             │   129 │   # a coroutine to run. Onc │
                             │   130 │   # switches back to this g │
                             │   131 │   # then returned to the ca │
                             │ ❱ 132 │   return current.parent.swi │
                             │       # noqa: E501                  │
                             │   133                               │
                             │   134                               │
                             │   135 def await_fallback(awaitable: │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/sqlalchemy/util/_concurrency_p │
                             │ y3k.py:196 in greenlet_spawn        │
                             │                                     │
                             │   193 │   │   try:                  │
                             │   194 │   │   │   # wait for a coro │
                             │   195 │   │   │   # result back to  │
                             │ ❱ 196 │   │   │   value = await res │
                             │   197 │   │   except BaseException: │
                             │   198 │   │   │   # this allows an  │
                             │   199 │   │   │   # the moderated g │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/psycopg/cursor_async.py:97 in  │
                             │ execute                             │
                             │                                     │
                             │    94 │   │   │   │   │   self._exe │
                             │    95 │   │   │   │   )             │
                             │    96 │   │   except e._NO_TRACEBAC │
                             │ ❱  97 │   │   │   raise ex.with_tra │
                             │    98 │   │   return self           │
                             │    99 │                             │
                             │   100 │   async def executemany(    │
                             ╰─────────────────────────────────────╯
                             ProgrammingError:
                             (psycopg.errors.UndefinedTable)
                             relation "user" does not exist
                             LINE 2: FROM "user"
                                          ^
                             [SQL: SELECT "user".id,
                             "user".username, "user".password,
                             "user".profile_image, "user".is_active,
                             "user".is_superuser, "user".create_at,
                             "user".updated_at,
                             "user".last_login_at,
                             "user".store_api_key, "user".optins
                             FROM "user"
                             WHERE "user".username =
                             %(username_1)s::VARCHAR]
                             [parameters: {'username_1':
                             'langflow'}]
                             (Background on this error at:
                             https://sqlalche.me/e/20/f405)

                             The above exception was the direct
                             cause of the following exception:

                             ╭─ Traceback (most recent call last) ─╮
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/main.py:240 in        │
                             │ lifespan                            │
                             │                                     │
                             │   237 │   │   │   │   # Step 2: Cle │
                             │   238 │   │   │   │   with shutdown │
                             │   239 │   │   │   │   │   try:      │
                             │ ❱ 240 │   │   │   │   │   │   await │
                             │   241 │   │   │   │   │   except as │
                             │   242 │   │   │   │   │   │   logge │
                             │   243                               │
                             │                                     │
                             │ /usr/local/lib/python3.12/asyncio/t │
                             │ asks.py:520 in wait_for             │
                             │                                     │
                             │    517 │   │   │   raise TimeoutErr │
                             │    518 │                            │
                             │    519 │   async with timeouts.time │
                             │ ❱  520 │   │   return await fut     │
                             │    521                              │
                             │    522 async def _wait(fs, timeout, │
                             │    523 │   """Internal helper for w │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/services/utils.py:135 │
                             │  in teardown_services               │
                             │                                     │
                             │   132 async def teardown_services() │
                             │   133 │   """Teardown all the servi │
                             │   134 │   async with get_db_service │
                             │ ❱ 135 │   │   await teardown_superu │
                             │   136 │                             │
                             │   137 │   from langflow.services.ma │
                             │   138                               │
                             │                                     │
                             │ /app/.venv/lib/python3.12/site-pack │
                             │ ages/langflow/services/utils.py:129 │
                             │  in teardown_superuser              │
                             │                                     │
                             │   126 │   │   │   logger.exception( │
                             │   127 │   │   │   await session.rol │
                             │   128 │   │   │   msg = "Could not  │
                             │ ❱ 129 │   │   │   raise RuntimeErro │
                             │   130                               │
                             │   131                               │
                             │   132 async def teardown_services() │
                             ╰─────────────────────────────────────╯
                             RuntimeError: Could not remove default
                             superuser.

Reproduction

  1. create a fresh postgres database
  2. create values.yaml asking langflow to use the postgres database & turning off autologin and setting LANGFLOW_SUPERUSER adn LANGFLOW_SUPERUSER_PASSWORD
  3. Install langflow on helm using kubernetes with Postgres

Expected behavior

Langflow should install with the requested superuser

Who can help?

@italojohnny @ogabrielluiz

Operating System

kubernetes

Langflow Version

langflow:1.5.0.post1

Python Version

None

Screenshot

No response

Flow File

No response

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