Skip to content

airflow db downgrade --to-version=2.10.5 fails, claiming NULLs that don't actually exist #57422

@Chais

Description

@Chais

Apache Airflow version

Other Airflow 2/3 version (please specify below)

If "Other Airflow 2/3 version" selected, which one?

3.0.2

What happened?

I wanted to upgrade our 2.10.5 to 2.11.0 but neglected to add --version 1.16.0 to helm upgrade, which resulted in it using the 1.18.0 chart. It ran the DB migrations to 3.0.2.
I'm now stuck trying to downgrade the DB back to 2.10.5, but get the following error:

sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) column "task_instance_id" of relation "task_instance_history" contains null values

[SQL: ALTER TABLE task_instance_history ADD COLUMN task_instance_id UUID NOT NULL]

which would be fine if it were actually true. I went into the shell to check:

airflow_db=> select count(*) from task_instance_history;
 count 
-------
  4450
(1 row)

airflow_db=> select count(*) from task_instance_history where task_instance_id is null;
 count 
-------
     0
(1 row)

airflow_db=> select count(*) from task_instance_history where task_instance_id is not null;
 count 
-------
  4450
(1 row)

So I'm not sure what Alembic is complaining about.

What you think should happen instead?

The migration 2 → 3 worked fine, so the reverse should work, as well.

How to reproduce

I don't think k8s has anything to do with this, so airflow standalone should do the trick. Just set up a 2.10.5 and upgrade to 3.0.2. A postgres DB might be necessary, though.
Having some entries in task_instance_history may be helpful.

Operating System

Worker runs Debian 12, host runs CentOS 7

Versions of Apache Airflow Providers

apache-airflow-providers-common-sql==1.27.1
apache-airflow-providers-odbc==4.10.0
apache-airflow-providers-postgres==6.2.0

Deployment

Official Apache Airflow Helm Chart

Deployment details

helm version
version.BuildInfo{Version:"v3.17.2", GitCommit:"cc0bbbd6d6276b83880042c1ecb34087e84d41eb", GitTreeState:"clean", GoVersion:"go1.23.7"}

Extended image:

FROM apache/airflow:slim-2.11.0-python3.12

USER root
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libkrb5-dev \
        htop \
    && apt-get autoremove -yqq --purge \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

USER airflow
RUN pip install --no-cache-dir python-socks apache-airflow[celery,imap,postgres,samba,sftp,ssh,statsd,tableau]==${AIRFLOW_VERSION} elasticsearch presto-python-client confluent-kafka

USER root

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions