kaxil commented on a change in pull request #6788: WIP: [AIRFLOW-5944] Rendering templated_fields without accessing DAG files URL: https://github.com/apache/airflow/pull/6788#discussion_r384646459
########## File path: airflow/models/dagrun.py ########## @@ -419,6 +420,17 @@ def verify_integrity(self, session=None): 1, 1) ti = TaskInstance(task, self.execution_date) session.add(ti) + session.commit() + + # ToDo: Store only Last X number (maybe 10 or 100) TIs for a task + rtif = session.query(RenderedTaskInstanceFields).filter( + RenderedTaskInstanceFields.dag_id == ti.dag_id, + RenderedTaskInstanceFields.task_id == ti.task_id, + RenderedTaskInstanceFields.execution_date == ti.execution_date, + ).first() Review comment: I can use the following but according to https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.exists we will need to further modify it >Note that some databases such as SQL Server don’t allow an EXISTS expression to be present in the columns clause of a SELECT. To select a simple boolean value based on the exists as a WHERE, use literal(): ```python rtif = session.query(session.query(RenderedTaskInstanceFields).filter( RenderedTaskInstanceFields.dag_id == ti.dag_id, RenderedTaskInstanceFields.task_id == ti.task_id, RenderedTaskInstanceFields.execution_date == ti.execution_date, ).exists()).scalar() ``` We might need to change it as follows for it work on SQL Server: ```python rtif = session.query(literal(True)).filter(session.query(RenderedTaskInstanceFields).filter( RenderedTaskInstanceFields.dag_id == ti.dag_id, RenderedTaskInstanceFields.task_id == ti.task_id, RenderedTaskInstanceFields.execution_date == ti.execution_date, ).exists()).scalar() ``` WDYT? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services