kalluripradeep opened a new pull request, #61019:
URL: https://github.com/apache/airflow/pull/61019
Fixes #60763
## Problem
When upgrading from Airflow 2.x to 3.0.6 and removing DAGs at the same time,
the removed DAGs are not deactivated and remain visible in the UI.
**Root Cause:**
DAGs from Airflow 2.x have `bundle_name = NULL`. The deactivation logic in
`deactivate_stale_dags()` only queries DAGs where
`bundle_name.in_(bundle_names)`, which completely excludes legacy DAGs with
NULL bundle_name.
```python
# Current code (line 321)
.where(~DagModel.is_stale, DagModel.bundle_name.in_(bundle_names))
```
This query ignores all DAGs with `bundle_name = NULL`, so they're never
checked for deactivation.
## Solution
Modified the query to also include DAGs with NULL bundle_name:
```python
# Fixed code
.where(
~DagModel.is_stale,
(DagModel.bundle_name.in_(bundle_names)) |
(DagModel.bundle_name.is_(None)),
)
```
This ensures that legacy DAGs from 2.x are included in the deactivation
check, so removed DAGs are properly deactivated during upgrades.
## Changes
- Updated `deactivate_stale_dags()` in
`airflow-core/src/airflow/dag_processing/manager.py`
- Added condition `| (DagModel.bundle_name.is_(None))` to include legacy
DAGs in deactivation query
## Context
- **Airflow 3.0.x**: DAGs from 2.x retain `bundle_name = NULL`
- **Airflow 3.1.0+**: Migration 0082 sets NULL bundle_names to
`'dags-folder'` by default
- This fix is needed for users upgrading to 3.0.x versions
## Testing
**Reproduction (as described in issue):**
1. Create Airflow 2.x environment with DAGs
2. Upgrade to 3.0.6 and remove some DAGs
3. Verify removed DAGs are not deactivated (bug)
**Expected result after fix:**
- Removed DAGs with NULL bundle_name should be properly deactivated
- DAGs should be marked as `is_stale=True` and cleared from UI
## Related
- Addresses migration issue reported by @deepak4babu
- Related to migration 0082 (Airflow 3.1.0) which sets default bundle_name
- Improves upgrade experience from 2.x to 3.0.x
--
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]