This repository contains the demo for the Best practices for Upgrading to Airflow 3 webinar.
my_legacy_dag.py- Legacy DAG that runs in Airflow 2 but not in Airflow 3, demonstrating deprecated syntax and patternsmy_fixed_dag.py- Fixed version of the legacy DAG that works in Airflow 3, showing the necessary syntax updatesmy_direct_db_access_dag.py- Demonstrates bad practice of direct metadatabase access (works in <3.0, removed in 3.0)my_dag_using_the_rest_api.py- Shows the recommended approach using Airflow REST API to access metadata in Airflow 3
from airflow.decorators→from airflow.sdkschedule_interval→scheduleexecution_date→logical_datedays_ago()→datetime()Dataset→AssetBashOperatorimport path updated
-
Fork this repo and clone this branch (
best-practices-for-upgrading-to-airflow-3) to your local machine. -
Make sure you have the Astro CLI installed and are at least on version 1.34.0 to be able to run Airflow 3.
-
Start the Airflow 2 project with
astro dev start
The Airflow 3 webserver with the Airflow UI will be available at
localhost:8080log in withadminas the username and password. Test out the two dags that work with Airflow 2. -
Run
astro dev killto reset the project. -
Switch the Dockerfile to the Airflow 3 image.
-
Run
astro dev startto start up the project with Airflow 3. -
Run the 3 DAGs. The
my_direct_db_access_dagwill fail because direct DB access is not allowed in Airflow 3. Note that you will likely need to adjust theHOSTvariable in themy_dag_using_the_rest_apito be able to query your Airflow environment. -
Install ruff and use
ruff check dags/my_legacy_dag.pyto see the ruff linter pointing out issues with the legacy dag.