Zingeryo opened a new issue, #56647:
URL: https://github.com/apache/airflow/issues/56647

   ### Apache Airflow version
   
   3.1.0
   
   ### If "Other Airflow 2/3 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   I have an issue when trying to upgrade my Airflow 2.10.5 to 3.1.0. When i 
rub `airflow db migrate` i get the following error:
   ```
   Running airflow config list to create default config file if missing.
   
   The container is run as root user. For security, consider using a regular 
user account.
   
/home/airflow/.local/lib/python3.12/site-packages/airflow/configuration.py:2251 
FutureWarning: The 'log_filename_template' setting in [logging] has the old 
default value of 'dag_id={{ ti.dag_id }}/run_id={{ ti.run_id }}/task_id={{ 
ti.task_id }}/{% if ti.map_index >= 0 %}map_index={{ ti.map_index }}/{% endif 
%}attempt={{ try_number }}.log'. This value has been changed to 'dag_id={{ 
ti.dag_id }}/run_id={{ ti.run_id }}/task_id={{ ti.task_id }}/{% if ti.map_index 
>= 0 %}map_index={{ ti.map_index }}/{% endif %}attempt={{ 
try_number|default(ti.try_number) }}.log' in the running config, but please 
update your config.
   
/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py:591 
DeprecationWarning: The web_server_port option in [webserver] has been moved to 
the port option in [api] - the old setting has been used, but please update 
your config.
   
/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py:597 
DeprecationWarning: The workers option in [webserver] has been moved to the 
workers option in [api] - the old setting has been used, but please update your 
config.
   
/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py:609 
DeprecationWarning: The web_server_host option in [webserver] has been moved to 
the host option in [api] - the old setting has been used, but please update 
your config.
   
/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py:614 
DeprecationWarning: The access_logfile option in [webserver] has been moved to 
the access_logfile option in [api] - the old setting has been used, but please 
update your config.
   
/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py:629 
DeprecationWarning: The web_server_ssl_cert option in [webserver] has been 
moved to the ssl_cert option in [api] - the old setting has been used, but 
please update your config.
   
/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py:634 
DeprecationWarning: The web_server_ssl_key option in [webserver] has been moved 
to the ssl_key option in [api] - the old setting has been used, but please 
update your config.
   Traceback (most recent call last):
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", 
line 1910, in _execute_context
       self.dialect.do_execute(
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/default.py",
 line 736, in do_execute
       cursor.execute(statement, parameters)
   psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type json
   DETAIL:  Unicode low surrogate must follow a high surrogate.
   CONTEXT:  JSON data, line 1: "\udc94...
   
   
   The above exception was the direct cause of the following exception:
   
   Traceback (most recent call last):
     File "/home/airflow/.local/bin/airflow", line 7, in <module>
       sys.exit(main())
                ^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/__main__.py", line 
55, in main
       args.func(args)
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py", 
line 48, in command
       return func(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/cli.py", line 
111, in wrapper
       return f(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/providers_configuration_loader.py",
 line 55, in wrapped_function
       return func(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/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 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/commands/db_command.py",
 line 125, in run_db_migrate_command
       command(
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/session.py", 
line 101, in wrapper
       return func(*args, session=session, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/db.py", line 
1142, in upgradedb
       command.upgrade(config, revision=to_revision or "heads")
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/command.py", line 
483, in upgrade
       script.run_env()
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/script/base.py", 
line 549, in run_env
       util.load_python_file(self.dir, "env.py")
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/util/pyfiles.py", 
line 116, in load_python_file
       module = load_module_py(module_id, path)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/util/pyfiles.py", 
line 136, 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 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/migrations/env.py", 
line 138, in <module>
       run_migrations_online()
     File 
"/home/airflow/.local/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 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/runtime/environment.py",
 line 946, in run_migrations
       self.get_context().run_migrations(**kw)
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/runtime/migration.py",
 line 627, in run_migrations
       step.migration_fn(**kw)
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/migrations/versions/0049_3_0_0_remove_pickled_data_from_xcom_table.py",
 line 101, in upgrade
       op.execute(
     File "<string>", line 8, in execute
     File "<string>", line 3, in execute
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/operations/ops.py", 
line 2591, in execute
       return operations.invoke(op)
              ^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/operations/base.py", 
line 441, in invoke
       return fn(self, operation)
              ^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/operations/toimpl.py",
 line 240, in execute_sql
       operations.migration_context.impl.execute(
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/ddl/impl.py", line 
253, in execute
       self._exec(sql, execution_options)
     File 
"/home/airflow/.local/lib/python3.12/site-packages/alembic/ddl/impl.py", line 
246, in _exec
       return conn.execute(construct, params)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/future/engine.py",
 line 286, in execute
       return self._execute_20(
              ^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", 
line 1710, in _execute_20
       return meth(self, args_10style, kwargs_10style, execution_options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", 
line 334, in _execute_on_connection
       return connection._execute_clauseelement(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", 
line 1577, in _execute_clauseelement
       ret = self._execute_context(
             ^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", 
line 1953, in _execute_context
       self._handle_dbapi_exception(
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", 
line 2134, in _handle_dbapi_exception
       util.raise_(
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/util/compat.py", 
line 211, in raise_
       raise exception
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", 
line 1910, in _execute_context
       self.dialect.do_execute(
     File 
"/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/default.py",
 line 736, in do_execute
       cursor.execute(statement, parameters)
   sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) 
invalid input syntax for type json
   DETAIL:  Unicode low surrogate must follow a high surrogate.
   CONTEXT:  JSON data, line 1: "\udc94...
   
   [SQL: 
               ALTER TABLE xcom
               ALTER COLUMN value TYPE JSONB
               USING CASE
                   WHEN value IS NOT NULL THEN CAST(CONVERT_FROM(value, 'UTF8') 
AS JSONB)
                   ELSE NULL
               END
               ]
   (Background on this error at: https://sqlalche.me/e/14/9h9h)
   ```
   My db is postgres:15
   
   ### What you think should happen instead?
   
   Successful migration 
   
   ### How to reproduce
   
   Run `airflow db migrate` from airflow 2.10.5 db to airflow 3.1.0 db
   
   ### Operating System
   
   Ubuntu 24.04.3 LTS
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Docker-Compose
   
   ### Deployment details
   
   My docker-compose file:
   ```
   ---
   x-airflow-common:
     &airflow-common
     image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:3.1.0}
     env_file:
       - path: ./.env
     volumes:
       - ${AIRFLOW_PROJ_DIR:-.}/dags:/opt/airflow/dags
       - ${AIRFLOW_PROJ_DIR:-.}/logs:/opt/airflow/logs
       - ${AIRFLOW_PROJ_DIR:-.}/config:/opt/airflow/config
       - ${AIRFLOW_PROJ_DIR:-.}/plugins:/opt/airflow/plugins
       - ${AIRFLOW_PROJ_DIR:-.}/dbt:/opt/airflow/dbt
     user: "${AIRFLOW_UID:-50000}:0"
     depends_on:
       &airflow-common-depends-on
       redis:
         condition: service_healthy
   
   services:
     redis:
       image: redis:7.2-bookworm
       ports:
         - "6379:6379"
       healthcheck:
         test: ["CMD", "redis-cli", "ping"]
         interval: 10s
         timeout: 30s
         retries: 50
         start_period: 30s
       restart: always
   
     airflow-webserver:
       <<: *airflow-common
       command: config update
       network_mode: host
       volumes:
         - ${AIRFLOW_PROJ_DIR:-.}/dags:/opt/airflow/dags
         - 
${AIRFLOW_PROJ_DIR:-.}/webserver_config.py:/opt/airflow/webserver_config.py
         - ${AIRFLOW_PROJ_DIR:-.}/config:/opt/airflow/config
         - ${AIRFLOW_PROJ_DIR:-.}/logs:/opt/airflow/logs
         - ${AIRFLOW_PROJ_DIR:-.}/dbt:/opt/airflow/dbt
       healthcheck:
         test: ["CMD", "curl", "--fail", "http://localhost:8080/api/v2/version";]
         interval: 30s
         timeout: 10s
         retries: 5
         start_period: 30s
       restart: always
       depends_on:
         <<: *airflow-common-depends-on
         airflow-init:
           condition: service_completed_successfully
   
   
     airflow-scheduler:
       <<: *airflow-common
       command: scheduler
       network_mode: host
       healthcheck:
         test: ["CMD", "curl", "--fail", "http://localhost:8974/health";]
         interval: 30s
         timeout: 10s
         retries: 5
         start_period: 30s
       restart: always
       depends_on:
         <<: *airflow-common-depends-on
         airflow-init:
           condition: service_completed_successfully
   
     airflow-dag-processor:
       <<: *airflow-common
       command: dag-processor
       healthcheck:
         test: ["CMD-SHELL", 'airflow jobs check --job-type DagProcessorJob 
--hostname "$${HOSTNAME}"']
         interval: 30s
         timeout: 10s
         retries: 5
         start_period: 30s
       restart: always
       depends_on:
         <<: *airflow-common-depends-on
         airflow-init:
           condition: service_completed_successfully
   
     airflow-triggerer:
       <<: *airflow-common
       command: triggerer
       network_mode: host
       healthcheck:
         test: ["CMD-SHELL", 'airflow jobs check --job-type TriggererJob 
--hostname "$${HOSTNAME}"']
         interval: 30s
         timeout: 10s
         retries: 5
         start_period: 30s
       restart: always
   
     airflow-init:
       <<: *airflow-common
       entrypoint: /bin/bash
       network_mode: host
       command:
         - -c
         - |
           if [[ -z "${AIRFLOW_UID}" ]]; then
             echo
             echo -e "\033[1;33mWARNING!!!: AIRFLOW_UID not set!\e[0m"
             echo "If you are on Linux, you SHOULD follow the instructions 
below to set "
             echo "AIRFLOW_UID environment variable, otherwise files will be 
owned by root."
             echo "For other operating systems you can get rid of the warning 
with manually created .env file:"
             echo "    See: 
https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html#setting-the-right-airflow-user";
             echo
             export AIRFLOW_UID=$$(id -u)
           fi
           one_meg=1048576
           mem_available=$$(($$(getconf _PHYS_PAGES) * $$(getconf PAGE_SIZE) / 
one_meg))
           cpus_available=$$(grep -cE 'cpu[0-9]+' /proc/stat)
           disk_available=$$(df / | tail -1 | awk '{print $$4}')
           warning_resources="false"
           if (( mem_available < 4000 )) ; then
             echo
             echo -e "\033[1;33mWARNING!!!: Not enough memory available for 
Docker.\e[0m"
             echo "At least 4GB of memory required. You have $$(numfmt --to iec 
$$((mem_available * one_meg)))"
             echo
             warning_resources="true"
           fi
           if (( cpus_available < 2 )); then
             echo
             echo -e "\033[1;33mWARNING!!!: Not enough CPUS available for 
Docker.\e[0m"
             echo "At least 2 CPUs recommended. You have $${cpus_available}"
             echo
             warning_resources="true"
           fi
           if (( disk_available < one_meg * 10 )); then
             echo
             echo -e "\033[1;33mWARNING!!!: Not enough Disk space available for 
Docker.\e[0m"
             echo "At least 10 GBs recommended. You have $$(numfmt --to iec 
$$((disk_available * 1024 )))"
             echo
             warning_resources="true"
           fi
           if [[ $${warning_resources} == "true" ]]; then
             echo
             echo -e "\033[1;33mWARNING!!!: You have not enough resources to 
run Airflow (see above)!\e[0m"
             echo "Please follow the instructions to increase amount of 
resources available:"
             echo "   
https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html#before-you-begin";
             echo
           fi
           echo
           echo "Creating missing opt dirs if missing:"
           echo
           mkdir -v -p /opt/airflow/{logs,dags,plugins,config}
           echo
           echo "Airflow version:"
           /entrypoint airflow version
           echo
           echo "Files in shared volumes:"
           echo
           ls -la /opt/airflow/{logs,dags,plugins,config}
           echo
           echo "Running airflow config list to create default config file if 
missing."
           echo
           /entrypoint airflow config list >/dev/null
           echo
           echo "Files in shared volumes:"
           echo
           ls -la /opt/airflow/{logs,dags,plugins,config}
           echo
           echo "Change ownership of files in /opt/airflow to ${AIRFLOW_UID}:0"
           echo
           chown -R "${AIRFLOW_UID}:0" /opt/airflow/
           echo
           echo "Change ownership of files in shared volumes to 
${AIRFLOW_UID}:0"
           echo
           chown -v -R "${AIRFLOW_UID}:0" 
/opt/airflow/{logs,dags,plugins,config}
           echo
           echo "Files in shared volumes:"
           echo
           ls -la /opt/airflow/{logs,dags,plugins,config}
       # yamllint enable rule:line-length
       environment:
         _AIRFLOW_DB_MIGRATE: 'true'
         _AIRFLOW_WWW_USER_CREATE: 'true'
         _AIRFLOW_WWW_USER_USERNAME: ${_AIRFLOW_WWW_USER_USERNAME:-airflow}
         _AIRFLOW_WWW_USER_PASSWORD: ${_AIRFLOW_WWW_USER_PASSWORD:-airflow}
         _PIP_ADDITIONAL_REQUIREMENTS: ''
       user: "0:0"
   
       volumes:
         - ${AIRFLOW_PROJ_DIR:-.}:/sources
         - ${AIRFLOW_PROJ_DIR:-.}/dags:/opt/airflow/dags
         - 
${AIRFLOW_PROJ_DIR:-.}/webserver_config.py:/opt/airflow/webserver_config.py
         - ${AIRFLOW_PROJ_DIR:-.}/config:/opt/airflow/config
         - ${AIRFLOW_PROJ_DIR:-.}/logs:/opt/airflow/logs
         - ${AIRFLOW_PROJ_DIR:-.}/dbt:/opt/airflow/dbt
   
     airflow-cli:
       <<: *airflow-common
       profiles:
         - debug
       environment:
         CONNECTION_CHECK_MAX_COUNT: "0"
       # Workaround for entrypoint issue. See: 
https://github.com/apache/airflow/issues/16252
       command:
         - bash
         - -c
         - airflow
       depends_on:
         <<: *airflow-common-depends-on
   ```
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to