Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Upgrade Airflow to 2.3, python to 3.10 (#502)

Madison Swain-Bowden9dca8963cda9
diff --git a/docker/airflow/Dockerfile b/docker/airflow/Dockerfile
index 2d480768b..82b1b3f27 100644
--- a/docker/airflow/Dockerfile
+++ b/docker/airflow/Dockerfile
@@ -1,4 +1,4 @@
-FROM python:3.9-slim
+FROM python:3.10-slim
# Build-time arguments, with sensible defaults
ARG REQUIREMENTS_FILE=requirements_prod.txt
@@ -37,7 +37,7 @@ RUN useradd -m -d ${AIRFLOW_HOME} airflow && \
chown airflow:airflow ${OUTPUT_DIR}
USER airflow
-ARG AIRFLOW_VERSION=2.2.4
+ARG AIRFLOW_VERSION=2.3.0
WORKDIR ${AIRFLOW_HOME}
# Always add the prod req because the dev reqs depend on it for deduplication
COPY ${REQUIREMENTS_FILE} requirements_prod.txt ${AIRFLOW_HOME}/
diff --git a/docker/airflow/wait_for_db.py b/docker/airflow/wait_for_db.py
index 65b31b6a2..e7f61fbc9 100644
--- a/docker/airflow/wait_for_db.py
+++ b/docker/airflow/wait_for_db.py
@@ -13,7 +13,7 @@ logging.basicConfig(
logger = logging.getLogger(__file__)
TRIES = 10
-CONN_ID = os.getenv("AIRFLOW__CORE__SQL_ALCHEMY_CONN")
+CONN_ID = os.getenv("AIRFLOW__DATABASE__SQL_ALCHEMY_CONN")
def main():
@@ -26,6 +26,8 @@ def main():
def _wait_for_db(tries=TRIES, conn_id=CONN_ID):
+ if not conn_id:
+ raise ValueError("MetaDB connection ID not provided")
engine = db.create_engine(conn_id)
success = False
logger.info(f"Testing DB connection {conn_id}")
diff --git a/env.template b/env.template
index abebdc682..f50bbf02e 100644
--- a/env.template
+++ b/env.template
@@ -39,7 +39,7 @@ AIRFLOW_VAR_API_KEY_FREESOUND=not_set
########################################################################################
# Airflow primary metadata database
# Change the following line in prod to use the appropriate DB
-AIRFLOW__CORE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@postgres:5432/airflow
+AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@postgres:5432/airflow
# Remote logging connection ID
# Replace "access_key" and "secret+key" with the real values. Secret key must be URL-encoded
AIRFLOW_CONN_AWS_DEFAULT=aws://test_key:test_secret@?region_name=us-east-1&host=http://s3:5000
diff --git a/openverse_catalog/dags/common/provider_dag_factory.py b/openverse_catalog/dags/common/provider_dag_factory.py
index 9f83cabec..b2864fa25 100644
--- a/openverse_catalog/dags/common/provider_dag_factory.py
+++ b/openverse_catalog/dags/common/provider_dag_factory.py
@@ -61,7 +61,7 @@ from typing import Callable, Dict, List, Optional, Sequence
from airflow import DAG
from airflow.models import TaskInstance
from airflow.models.baseoperator import cross_downstream
-from airflow.operators.dummy import DummyOperator
+from airflow.operators.empty import EmptyOperator
from airflow.operators.python import PythonOperator
from airflow.utils.task_group import TaskGroup
from airflow.utils.trigger_rule import TriggerRule
@@ -393,7 +393,7 @@ def create_day_partitioned_ingestion_dag(
reingestion_day_list_list, main_function, ingestion_task_timeout
)
for i in range(len(ingest_operator_list_list) - 1):
- wait_operator = DummyOperator(
+ wait_operator = EmptyOperator(
task_id=f"wait_L{i}", trigger_rule=TriggerRule.ALL_DONE
)
cross_downstream(ingest_operator_list_list[i], [wait_operator])
diff --git a/requirements_prod.txt b/requirements_prod.txt
index 4664c850a..c3f17603a 100644
--- a/requirements_prod.txt
+++ b/requirements_prod.txt
@@ -1,4 +1,4 @@
-apache-airflow[amazon,postgres,http]==2.2.4
+apache-airflow[amazon,postgres,http]==2.3.0
lxml
psycopg2-binary
requests-file==1.5.1
diff --git a/tests/dags/common/sensors/test_single_run_external_dags_sensor.py b/tests/dags/common/sensors/test_single_run_external_dags_sensor.py
index 5928c6223..c5390c2bf 100644
--- a/tests/dags/common/sensors/test_single_run_external_dags_sensor.py
+++ b/tests/dags/common/sensors/test_single_run_external_dags_sensor.py
@@ -101,8 +101,9 @@ class TestExternalDAGsSensor(unittest.TestCase):
# Loads an example DAG which does not have a Sensor task.
with warnings.catch_warnings():
# TODO: As of 2.2.4, initializing the example DAGs emits deprecation
- # warnings for...(drumroll) Airflow operators 🙃 hopefully this is fixed
- # in 2.2.5 or something.
+ # TODO: warnings for...(drumroll) Airflow operators 🙃 hopefully this is
+ # TODO: fixed in 2.2.5 or something.
+ # TODO: Update: 2022-05-06/v2.3.0, still an issue!
warnings.simplefilter("ignore", category=DeprecationWarning)
dagbag = DagBag(dag_folder=DEV_NULL, include_examples=True)
bash_dag = dagbag.dags["example_bash_operator"]