amoghrajesh commented on code in PR #68218:
URL: https://github.com/apache/airflow/pull/68218#discussion_r3379167056
##########
airflow-core/tests/unit/utils/test_db_cleanup.py:
##########
@@ -878,6 +879,95 @@ def create_tis(base_date, num_tis,
run_type=DagRunType.SCHEDULED):
session.commit()
[email protected]_test
+class TestTaskStoreCleanup:
+ def test_expired_rows_deleted(self):
+ from datetime import timezone as dt_timezone
+
+ cfg = config_dict["task_store"]
+ now = pendulum.now(tz="UTC")
+ past = now.subtract(days=30)
+ future = now.add(days=30)
+
+ with create_session() as session:
+ bundle = DagBundleModel(name="ts_test_bundle")
+ session.add(bundle)
+ session.flush()
+
+ dag = DAG(dag_id="ts_test_dag")
+ dm = DagModel(dag_id="ts_test_dag", bundle_name="ts_test_bundle")
+ session.add(dm)
+ SerializedDagModel.write_dag(LazyDeserializedDAG.from_dag(dag),
bundle_name="ts_test_bundle")
+
+ dag_run = DagRun(
+ "ts_test_dag",
+ run_id="ts_test_run",
+ run_type=DagRunType.SCHEDULED,
+ start_date=past,
+ )
+ session.add(dag_run)
+ session.flush()
+
+ expired = TaskStoreModel(
+ dag_run_id=dag_run.id,
+ task_id="t1",
+ map_index=-1,
+ key="job_id",
+ dag_id="ts_test_dag",
+ run_id="ts_test_run",
+ value="job-expired",
+ updated_at=past.in_timezone(dt_timezone.utc),
+ expires_at=past.subtract(days=1).in_timezone(dt_timezone.utc),
+ )
+ never_expire = TaskStoreModel(
+ dag_run_id=dag_run.id,
+ task_id="t1",
+ map_index=-1,
+ key="result",
+ dag_id="ts_test_dag",
+ run_id="ts_test_run",
+ value="job-never-expire",
+ updated_at=past.in_timezone(dt_timezone.utc),
+ expires_at=None,
+ )
+ not_yet_expired = TaskStoreModel(
+ dag_run_id=dag_run.id,
+ task_id="t1",
+ map_index=-1,
+ key="future_key",
+ dag_id="ts_test_dag",
+ run_id="ts_test_run",
+ value="job-future",
+ updated_at=past.in_timezone(dt_timezone.utc),
+ expires_at=future.in_timezone(dt_timezone.utc),
+ )
+ session.add_all([expired, never_expire, not_yet_expired])
+ session.commit()
Review Comment:
This one is actually fine, the `session.commit()` here is inside the
`create_session()` block and flushes the test data before the block exits. The
`create_session` context manager does commit on `__exit__`, but committing
explicitly before that is harmless and makes the intent clear.
--
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]