run_id = self.run_id
        try:
            if hook_is_noop:
                session.bulk_insert_mappings(TI, tasks)
            else:
                session.bulk_save_objects(tasks)
            for task_type, count in created_counts.items():
                Stats.incr(f"task_instance_created-{task_type}", count, tags=self.stats_tags)
            session.flush()
        except IntegrityError:
            self.log.info(
                "Hit IntegrityError while creating the TIs for %s- %s",
                dag_id,
                run_id,
                exc_info=True,
            )
            self.log.info("Doing session rollback.")
            
            session.rollback()
    def _revise_map_indexes_if_mapped(self, task: Operator, *, session: Session) -> Iterator[TI]:
        """Check if task increased or reduced in length and handle appropriately.
        Task instances that do not already exist are created and returned if
        possible. Expansion only happens if all upstreams are ready; otherwise
        we delay expansion to the "last resort". See comments at the call site
        for more details.
        """
        from airflow.settings import task_instance_mutation_hook
        try:
            total_length = task.get_mapped_ti_count(self.run_id, session=session)
        except NotMapped: