potiuk commented on code in PR #59183:
URL: https://github.com/apache/airflow/pull/59183#discussion_r2602787179
##########
airflow-core/src/airflow/assets/manager.py:
##########
@@ -361,17 +431,28 @@ def _get_or_create_apdr(
.limit(1)
)
if latest_apdr and latest_apdr.created_dag_run_id is None:
- apdr = latest_apdr
- else:
- apdr = AssetPartitionDagRun(
- target_dag_id=target_dag.dag_id,
- created_dag_run_id=None,
- partition_key=target_key,
- )
- session.add(apdr)
- session.flush()
+ return latest_apdr
+
+ apdr = AssetPartitionDagRun(
+ target_dag_id=target_dag.dag_id,
+ created_dag_run_id=None,
+ partition_key=target_key,
+ )
+ session.add(apdr)
+ session.flush()
return apdr
+ @classmethod
+ def _lock_asset_row(cls, asset_id: int, session: Session) -> AssetModel:
+ """Lock the AssetModel row associated with this APDR operation."""
+ asset_model = with_row_locks(
+ query=select(AssetModel).where(AssetModel.id == asset_id),
Review Comment:
I think it would be a bit more efficient if we only retrieve id of the asset
model. We do not need the whole model here, and if we only return asset id, the
whole query (even for update) will only use index scan on primary key and not
retrieve the whole row.
--
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]