jainvaibhav62 opened a new pull request, #77566:
URL: https://github.com/apache/airflow/pull/77566
The Dags page folder tree (#68544) groups Dags by the directory of their
file, so where a Dag appears is tied to how the repository is laid out. Dags
generated from a single file, or kept in a flat layout, cannot be grouped the
way people want to browse them.
This adds a `display_folder` argument to `DAG` and `@dag`:
```python
with DAG("orders_etl", schedule=None, display_folder="team_a/etl"): ...
```
- A declared `display_folder` takes precedence over the file's directory in
the folders endpoint and the folder filter of the Dags page. Dags that declare
none keep the folder their file location gives them, so existing deployments
see no change and no backfill is needed.
- The value is normalized at parse time (surrounding `/` stripped); empty,
`.` and `..` segments raise `ValueError`.
- It is stored in a new nullable `dag.display_folder` column (migration
`0158`). An unset value is not serialized, so serialized Dag hashes of existing
Dags do not change.
- The name is `display_folder` rather than `folder` because `DAG.folder`
already exists as public API (the Dag file's directory, used for the template
search path and templates such as `{{ task.dag.folder }}`).
- The Go and TS SDKs pick the field up through their generated schema fields
(`DagSpec.DisplayFolder`, `displayFolder`).
- No frontend change: the existing folder tree consumes the endpoint and
filter, so there is no new UI to screenshot.
#### Checks run locally
- Task SDK `test_dag.py`: 127 passed
- `test_dag_serialization.py` + `test_dag_version_diff.py`: 833 passed
- `models/test_dag.py -k bulk_write_to_db`: 13 passed
- `api_fastapi/core_api/routes/ui/test_dags.py`: 118 passed
- `utils/test_db.py` + `dag_processing/test_collection.py`: 136 passed, 4
skipped
- TS SDK vitest: 998 passed
- mypy (`airflow-core`, `task-sdk`): passed
- prek pre-commit stage on the changed files: passed, except four hooks that
need breeze/Docker, which was not available locally: `generate-openapi-spec`,
`update-migration-references`, `check-schema-defaults`,
`check-tests-in-the-right-folders`. The migration reference doc and the private
UI OpenAPI spec (one query-parameter description changed) are therefore left
for those hooks/CI to regenerate.
Database tests ran on SQLite only.
#### Performance
Serialization and Dag processing are touched, so the paths were timed on
`main` and this branch, alternating 5 runs each, Dag with 50 tasks and no
`display_folder` (best of 5×20 calls per run, median of runs):
| Path | main | this PR | Δ |
|---|---|---|---|
| Build `DAG` with 50 tasks | 2.552 ms | 2.534 ms | -0.7% |
| `DagSerialization.to_dict` | 3.469 ms | 3.469 ms | +0.0% |
| `DagSerialization.from_dict` | 0.961 ms | 1.030 ms | +7.2% |
| `LazyDeserializedDAG.from_dag` | 3.528 ms | 3.515 ms | -0.4% |
| Control (`json.dumps`, untouched) | 0.126 ms | 0.129 ms | +2.4% |
The `from_dict` runs overlap (main 0.93–1.13 ms, this PR 0.97–1.12 ms); the
only added work there is one more key in the set difference at
`serialized_objects.py` that sets absent fields to `None`, so the median
difference is attributed to run-to-run noise.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 5.5)
Generated-by: Claude Code (Opus 5.5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]