potiuk commented on code in PR #28900:
URL: https://github.com/apache/airflow/pull/28900#discussion_r1311282316
##########
airflow/models/taskinstance.py:
##########
@@ -787,6 +788,38 @@ def error(self, session: Session = NEW_SESSION) -> None:
session.merge(self)
session.commit()
+ @classmethod
+ @internal_api_call
+ @provide_session
+ def get_task_instance(
+ cls,
+ dag_id: str,
+ run_id: str,
+ task_id: str,
+ map_index: int,
+ select_columns: bool = False,
+ lock_for_update: bool = False,
+ session: Session = NEW_SESSION,
+ ) -> TaskInstance | None:
+ query = (
+ session.query(*TaskInstance.__table__.columns) if select_columns
else session.query(TaskInstance)
+ )
+ query = query.filter_by(
+ dag_id=dag_id,
+ run_id=run_id,
+ task_id=task_id,
+ map_index=map_index,
+ )
+
+ if lock_for_update:
Review Comment:
I think a good idea would be to split that to two methods. We definitely do
not want to have a case where we have lock_for_update=True over the internal
API so rather than just leave it here, I think we could probably duplicate that
method (with some DRY-internal method query) into:
```
# no internal api
@provide_session
def get_task_instance_with_lock(
cls,
dag_id: str,
run_id: str,
task_id: str,
map_index: int,
select_columns: bool = False,
session: Session = NEW_SESSION)
_get_task_instance(...., lock_for_update=True)
@provide_session
@internal_api_call
def get_task_instance_no_lock(
cls,
dag_id: str,
run_id: str,
task_id: str,
map_index: int,
select_columns: bool = False,
session: Session = NEW_SESSION):
_get_task_instance(...., lock_for_update=False)
def _get_task_instance(...
```
--
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]