ashb commented on code in PR #68705:
URL: https://github.com/apache/airflow/pull/68705#discussion_r3758401189
##########
airflow-core/src/airflow/models/backfill.py:
##########
@@ -677,34 +677,41 @@ def _create_backfill(
)
session.add(br)
session.commit()
+ backfill_id = br.id
- session.scalars(select(DagModel).where(DagModel.dag_id ==
dag_id)).one()
-
- dagrun_info_list = _get_info_list(
- from_date=from_date,
- to_date=to_date,
- reverse=reverse,
- dag=dag,
- )
- if not dagrun_info_list:
- raise RuntimeError(f"No runs to create for Dag {dag_id}")
+ try:
+ session.scalars(select(DagModel).where(DagModel.dag_id ==
dag_id)).one()
- first_info = dagrun_info_list[0]
- if first_info.partition_key:
- _create_runs_partitioned(
- br=br,
+ dagrun_info_list = _get_info_list(
+ from_date=from_date,
+ to_date=to_date,
+ reverse=reverse,
dag=dag,
- dagrun_info_list=dagrun_info_list,
- session=session,
- )
- else:
- _create_runs_non_partitioned(
- br=br,
- dag=dag,
- dagrun_info_list=dagrun_info_list,
- run_on_latest_version=run_on_latest_version,
- session=session,
)
+ if not dagrun_info_list:
+ raise RuntimeError(f"No runs to create for Dag {dag_id}")
+
+ first_info = dagrun_info_list[0]
+ if first_info.partition_key:
+ _create_runs_partitioned(
+ br=br,
+ dag=dag,
+ dagrun_info_list=dagrun_info_list,
+ session=session,
+ )
+ else:
+ _create_runs_non_partitioned(
+ br=br,
+ dag=dag,
+ dagrun_info_list=dagrun_info_list,
+ run_on_latest_version=run_on_latest_version,
+ session=session,
+ )
+ except Exception:
+ session.rollback()
+ session.execute(sa.delete(Backfill).where(Backfill.id ==
backfill_id))
Review Comment:
This doesn't feel like the right fix. Please change things so that it is all
in a single transaction so that "simple rollback" is enough to remove the row.
A `session.flush()` instead of a session.commit further up is I think enough go
get br.id populated.
--
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]