GitHub user aipatr edited a discussion: Trying to upgrade to Airflow 3
I am trying to upgrade to airflow 3.0, I updated the config, all dependency are
up to date according to the constraint file. I am in a virtual environment.
PostgreSql version 17, the function is there, SQLAlchemy updated, everything
looks in order but when I try to migrate my db this happens. Could you help me?
Operating system is Ubuntu.
(pytorch) sysgen@a0521139901:~/airflow$ airflow db migrate
DB: postgresql+psycopg2://airflow:***@localhost/airflow
Performing upgrade to the metadata database
postgresql+psycopg2://airflow:***@localhost/airflow
[2025-04-24T13:48:41.727+0200] {migration.py:207} INFO - Context impl
PostgresqlImpl.
[2025-04-24T13:48:41.727+0200] {migration.py:210} INFO - Will assume
transactional DDL.
[2025-04-24T13:48:41.740+0200] {db.py:1135} INFO - Migrating the Airflow
database
[2025-04-24T13:48:41.756+0200] {migration.py:207} INFO - Context impl
PostgresqlImpl.
[2025-04-24T13:48:41.756+0200] {migration.py:210} INFO - Will assume
transactional DDL.
[2025-04-24T13:48:41.775+0200] {migration.py:618} INFO - Running upgrade
05234396c6fc -> d59cbbef95eb, Add UUID primary key to ``task_instance`` table.
Traceback (most recent call last):
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/base.py",
line 1910, in _execute_context
self.dialect.do_execute(
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/default.py",
line 736, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist
LINE 1: SELECT unix_time_ms || substring(uuid_send(gen_random_uuid()...
^
HINT: No function matches the given name and argument types. You might need to
add explicit type casts.
QUERY: SELECT unix_time_ms || substring(uuid_send(gen_random_uuid()) FROM 1
FOR 5) ||
substring(uuid_send(gen_random_uuid()) FROM 12 FOR 5)
CONTEXT: PL/pgSQL function uuid_generate_v7(timestamp with time zone) line 12
at assignment
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/miniconda3/envs/pytorch/bin/airflow", line 8, in <module>
sys.exit(main())
^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/__main__.py",
line 55, in main
args.func(args)
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/cli/cli_config.py",
line 48, in command
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/utils/cli.py",
line 111, in wrapper
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/utils/providers_configuration_loader.py",
line 55, in wrapped_function
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/cli/commands/db_command.py",
line 197, in migratedb
run_db_migrate_command(args, db.upgradedb, _REVISION_HEADS_MAP)
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/cli/commands/db_command.py",
line 125, in run_db_migrate_command
command(
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/utils/session.py",
line 101, in wrapper
return func(*args, session=session, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/utils/db.py",
line 1142, in upgradedb
command.upgrade(config, revision=to_revision or "heads")
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/alembic/command.py",
line 408, in upgrade
script.run_env()
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/alembic/script/base.py",
line 586, in run_env
util.load_python_file(self.dir, "env.py")
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/alembic/util/pyfiles.py",
line 95, in load_python_file
module = load_module_py(module_id, path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/alembic/util/pyfiles.py",
line 113, in load_module_py
spec.loader.exec_module(module) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap_external>", line 999, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/migrations/env.py",
line 138, in <module>
run_migrations_online()
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/migrations/env.py",
line 132, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/alembic/runtime/environment.py",
line 946, in run_migrations
self.get_context().run_migrations(**kw)
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/alembic/runtime/migration.py",
line 623, in run_migrations
step.migration_fn(**kw)
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py",
line 210, in upgrade
result = conn.execute(
^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/future/engine.py",
line 286, in execute
return self._execute_20(
^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/base.py",
line 1710, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/sql/elements.py",
line 334, in _execute_on_connection
return connection._execute_clauseelement(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/base.py",
line 1577, in _execute_clauseelement
ret = self._execute_context(
^^^^^^^^^^^^^^^^^^^^^^
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/base.py",
line 1953, in _execute_context
self._handle_dbapi_exception(
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/base.py",
line 2134, in _handle_dbapi_exception
util.raise_(
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/util/compat.py",
line 211, in raise_
raise exception
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/base.py",
line 1910, in _execute_context
self.dialect.do_execute(
File
"/opt/miniconda3/envs/pytorch/lib/python3.12/site-packages/sqlalchemy/engine/default.py",
line 736, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) function
gen_random_uuid() does not exist
LINE 1: SELECT unix_time_ms || substring(uuid_send(gen_random_uuid()...
^
HINT: No function matches the given name and argument types. You might need to
add explicit type casts.
QUERY: SELECT unix_time_ms || substring(uuid_send(gen_random_uuid()) FROM 1
FOR 5) ||
substring(uuid_send(gen_random_uuid()) FROM 12 FOR 5)
CONTEXT: PL/pgSQL function uuid_generate_v7(timestamp with time zone) line 12
at assignment
[SQL:
WITH cte AS (
SELECT ctid
FROM task_instance
WHERE id IS NULL
LIMIT %(batch_size)s
)
UPDATE task_instance
SET id = uuid_generate_v7(coalesce(queued_dttm, start_date,
clock_timestamp()))
FROM cte
WHERE task_instance.ctid = cte.ctid
]
[parameters: {'batch_size': 10000}]
(Background on this error at: https://sqlalche.me/e/14/f405)
GitHub link: https://github.com/apache/airflow/discussions/49707
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]