You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "1fanwang (via GitHub)" <gi...@apache.org> on 2026/09/26 02:40:36 UTC

[PR] Support rendered_task_instance_fields in airflow db clean [airflow]

1fanwang opened a new pull request, #73745:
URL: https://github.com/apache/airflow/pull/73745

   Operators running `airflow db clean` cannot prune `rendered_task_instance_fields` (RTIF) independently of `task_instance`. Because RTIF tables store full rendered templates, configuration payloads, and Kubernetes pod specs for every task attempt, they grow rapidly into gigabytes of database storage while task instances are retained for audit. `airflow db clean --tables rendered_task_instance_fields` fails with `No tables selected for db cleanup`.
   
   ### What changed
   
   This adds support for cleaning child tables that lack an independent recency timestamp by allowing `_TableConfig` to join a parent recency table on primary key columns. `rendered_task_instance_fields` is configured to join `task_instance` on composite keys `(dag_id, task_id, run_id, map_index)` and filter by `task_instance.start_date`, enabling independent RTIF pruning while retaining task instances.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes
   
   Generated-by: GitHub Copilot CLI following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   ---
   
   ### Testing Done
   
   #### Before (main branch)
   
   Attempting to clean `rendered_task_instance_fields` on the main branch fails because the table is unregistered:
   
   ```bash
   airflow db clean --tables rendered_task_instance_fields --clean-before-timestamp 2026-01-01 -y
   ```
   
   ```
   SystemExit: No tables selected for db cleanup. Please choose valid table names.
   ```
   
   #### After (this branch)
   
   Executed database setup with 1 task instance and 1 rendered task instance field row:
   
   ```bash
   python /tmp/reproduce_rtif_cleanup.py
   ```
   
   ```
   Seed complete: inserted 1 task_instance and 1 rendered_task_instance_fields row.
   ```
   
   CLI cleanup purges expired RTIF rows into the archive table while leaving parent task instances intact:
   
   ```bash
   airflow db clean --tables rendered_task_instance_fields --clean-before-timestamp 2026-01-01 -y
   ```
   
   ```
   Checking table rendered_task_instance_fields
   Found 1 rows meeting deletion criteria.
   Performing Delete...
   Moving data to table _airflow_deleted__rendered_task_instance_fields__20260926014710
   Finished Performing Delete
   ```
   
   Inspected post-clean row counts:
   
   ```bash
   python -c "
   from sqlalchemy import func, select
   from airflow.models import TaskInstance
   from airflow.models.renderedtifields import RenderedTaskInstanceFields
   from airflow.utils.session import create_session
   
   with create_session() as session:
       ti_cnt = session.scalar(select(func.count(TaskInstance.id)).where(TaskInstance.dag_id == 'rtif_demo'))
       rtif_cnt = session.scalar(select(func.count(RenderedTaskInstanceFields.dag_id)).where(RenderedTaskInstanceFields.dag_id == 'rtif_demo'))
       print(f'task_instance remaining: {ti_cnt}')
       print(f'rendered_task_instance_fields remaining: {rtif_cnt}')
   "
   ```
   
   ```
   task_instance remaining: 1
   rendered_task_instance_fields remaining: 0
   ```
   
   <details>
   <summary>Reproducer source: reproduce_rtif_cleanup.py</summary>
   
   ```python
   #!/usr/bin/env python3
   import pendulum
   from airflow.models import DAG, DagModel, DagRun, TaskInstance
   from airflow.models.dag_version import DagVersion
   from airflow.models.dagbundle import DagBundleModel
   from airflow.models.renderedtifields import RenderedTaskInstanceFields
   from airflow.models.serialized_dag import SerializedDagModel
   from airflow.providers.standard.operators.python import PythonOperator
   from airflow.serialization.serialized_objects import LazyDeserializedDAG
   from airflow.utils.session import create_session
   from airflow.utils.types import DagRunType
   
   base_date = pendulum.DateTime(2023, 1, 1, tzinfo=pendulum.timezone("UTC"))
   bundle_name = "dags"
   
   with create_session() as session:
       session.add(DagBundleModel(name=bundle_name))
       session.flush()
   
       dag_id = "rtif_demo"
       dag = DAG(dag_id=dag_id)
       dag.fileloc = __file__
       dm = DagModel(dag_id=dag_id, bundle_name=bundle_name)
       session.add(dm)
       SerializedDagModel.write_dag(LazyDeserializedDAG.from_dag(dag), bundle_name=bundle_name)
       dag_version = DagVersion.get_latest_version(dag.dag_id)
   
       dr = DagRun(dag.dag_id, run_id="run_1", run_type=DagRunType.SCHEDULED, start_date=base_date)
       ti = TaskInstance(
           PythonOperator(task_id="task_1", python_callable=print),
           run_id=dr.run_id,
           dag_version_id=dag_version.id,
       )
       ti.dag_id = dag.dag_id
       ti.start_date = base_date
       session.add(dr)
       session.add(ti)
       session.flush()
   
       rtif = RenderedTaskInstanceFields(ti=ti, render_templates=False, rendered_fields={"sql": "SELECT 1"})
       session.add(rtif)
       session.commit()
       print("Seed complete: inserted 1 task_instance and 1 rendered_task_instance_fields row.")
   ```
   </details>
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support rendered_task_instance_fields in airflow db clean [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #73745:
URL: https://github.com/apache/airflow/pull/73745#issuecomment-5847601160

   Hello @1fanwang - thank you for your contributions to Apache Airflow!
   
   The Airflow community has introduced a limit of **5 open pull requests at a time** for contributors without write access to the repository. You currently have 8 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:
   
   * #73743 - Fix airflowctl dags get-tags crashing whenever a Dag has tags
   * #73745 - Support rendered_task_instance_fields in airflow db clean
   
   This is the **second time** we are doing this closure - the original one was not effective because of a bug in our infrastructure deployment. Sorry for the extra noise!
   
   These pull requests stay open because maintainers are already engaged in them - they count towards your limit:
   
   * #68936 - Add durable option to TriggerDagRunOperator to reconnect on retry
   * #68952 - Let deferrable tasks reconnect without polling
   * #71307 - Retry transient database errors in the metastore secrets backend
   * #72907 - Return 404 instead of 500 when DagRun is missing in Execution API
   * #72908 - Edge: Return 404 for missing task logs and emit failed job metrics
   * #72925 - Edge: Return 400 instead of 500 on invalid worker version
   
   This is **not** a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.
   
   What we ask you to do is to make your **first prioritization decision**: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or `gh pr reopen <PR_NUMBER> --repo apache/airflow`. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.
   
   While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.
   
   Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support rendered_task_instance_fields in airflow db clean [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk closed pull request #73745: Support rendered_task_instance_fields in airflow db clean
URL: https://github.com/apache/airflow/pull/73745


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org