Prab-27 commented on code in PR #68218:
URL: https://github.com/apache/airflow/pull/68218#discussion_r3373912464


##########
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:
   Do we need to `session.commit()` here ? since this covers under 
`create_session ` here 
https://github.com/apache/airflow/blob/cc13ca22b0287ee0d3995a53b793e7ec06fd20b4/airflow-core/src/airflow/utils/session.py#L43
   



-- 
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]

Reply via email to