We can avoid processing the relationship when the old state was already written to the database which will common case with a commit interval of 1s. Since we already know the value for old_state_id we can use it instead of asking sqlalchemy to process the relationship at flush/commit time which can significantly speed up sqlalchemy's _emit_insert_statements implementation.