ferruzzi commented on code in PR #50677:
URL: https://github.com/apache/airflow/pull/50677#discussion_r2103862801
##########
airflow-core/src/airflow/models/deadline.py:
##########
@@ -183,3 +156,52 @@ def serialize_deadline_alert(self):
"callback_kwargs": self.callback_kwargs,
}
)
+
+
+@provide_session
+def _fetch_from_db(model_reference: Column, session=None, **conditions) ->
datetime:
+ """
+ Fetch a datetime value from the database using the provided model
reference and filtering conditions.
+
+ For example, to fetch a TaskInstance's start_date:
+ _fetch_from_db(
+ TaskInstance.start_date, dag_id='example_dag',
task_id='example_task', run_id='example_run'
+ )
+
+ This generates SQL equivalent to:
+ SELECT start_date
+ FROM task_instance
+ WHERE dag_id = 'example_dag'
+ AND task_id = 'example_task'
+ AND run_id = 'example_run'
+
+ :param model_reference: SQLAlchemy Column to select (e.g.,
DagRun.logical_date, TaskInstance.start_date)
+ :param conditions: Filtering conditions applied as equality comparisons in
the WHERE clause.
+ Multiple conditions are combined with AND.
+ :param session: SQLAlchemy session (auto-provided by decorator)
+ """
+ query = select(model_reference)
+
+ for key, value in conditions.items():
+ query = query.where(getattr(model_reference.class_, key) == value)
Review Comment:
Do you feel strongly about this one? I find your version harder to read for
some reason, but they are functionally equivalent so I can do it if you want.
--
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]