You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/02/24 21:57:47 UTC

[GitHub] [airflow] saguziel commented on a change in pull request #7370: [AIRFLOW-6590] Use batch db operations in jobs

saguziel commented on a change in pull request #7370: [AIRFLOW-6590] Use batch db operations in jobs
URL: https://github.com/apache/airflow/pull/7370#discussion_r383539224
 
 

 ##########
 File path: airflow/jobs/scheduler_job.py
 ##########
 @@ -1270,20 +1276,17 @@ def _change_state_for_executable_task_instances(self, task_instances,
             return []
 
         # set TIs to queued state
-        for task_instance in tis_to_set_to_queued:
-            task_instance.state = State.QUEUED
-            task_instance.queued_dttm = timezone.utcnow()
-            session.merge(task_instance)
+        filter_for_tis = TI.filter_for_tis(tis_to_set_to_queued)
+        session.query(TI).filter(filter_for_tis).update(
+            {TI.state: State.QUEUED, TI.queued_dttm: timezone.utcnow()}, synchronize_session=False
+        )
+        session.commit()
 
         # Generate a list of SimpleTaskInstance for the use of queuing
         # them in the executor.
-        simple_task_instances = [SimpleTaskInstance(ti) for ti in
-                                 tis_to_set_to_queued]
+        simple_task_instances = [SimpleTaskInstance(ti) for ti in tis_to_set_to_queued]
 
 Review comment:
   @nuclearpinguin  I believe that this should  be before session.commit(). 
   
   Session.commit() should flush the session, and then sqlalchemy will need to requery each TI individually to reconstruct the STI

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services