#1638 Move ComponentBuildTrace creation from before_commit to before_flush
Merged 3 years ago by breilly. Opened 3 years ago by jobrauer.
jobrauer/fm-orchestrator switch_to_before_flush  into  master

@@ -1302,7 +1302,7 @@ 

          )

  

  

- def session_before_commit_handlers(session):

+ def session_before_flush_handlers(session, flush_context, instances):

      # new and updated items

      for item in set(session.new) | set(session.dirty):

          # handlers for component builds

@@ -8,7 +8,7 @@ 

  

  from module_build_service.common.config import conf

  from module_build_service.common.models import (

-     session_before_commit_handlers, send_message_after_module_build_state_change

+     session_before_flush_handlers, send_message_after_module_build_state_change

  )

  

  __all__ = ("db_session",)
@@ -19,7 +19,7 @@ 

      Starts listening for events related to the database session.

      """

      event_hooks = (

-         ("before_commit", session_before_commit_handlers),

+         ("before_flush", session_before_flush_handlers),

          ("after_commit", send_message_after_module_build_state_change),

      )

  

Since ComponentBuildTrace(s) get created with db_session.commit() call,
is is not possible to commit more items in bulk if they already have been flushed.

Current unit-tests' setup can be significantly sped up if items can be quickly
flushed on the fly and bulk-commited only once at the end. Moreover in general it
seems more appropriate/safer to handle this in before_flush as any implicit
or accidental flush could cause new build traces not to be created at all. As flush
is implicitly called before every commit anyway, this change shouldn't pose any harm.

rebased onto 1ce34b998532e770595cddc54cd452d3ee17e19e

3 years ago

@mikem @breilly please can you check this PR? This is opened 22 days ago. Thank you.

LGTM, @jobrauer could you please rebase?

rebased onto 8a5bf3a

3 years ago

Pull-Request has been merged by breilly

3 years ago