def per_state_flush_actions(self, uow, states, isdelete):

        parent_base_mapper = self.parent.primary_base_mapper
        child_base_mapper = self.mapper.primary_base_mapper
        child_saves = unitofwork.SaveUpdateAll(uow, child_base_mapper)
        child_deletes = unitofwork.DeleteAll(uow, child_base_mapper)

        # locate and disable the aggregate processors
        # for this dependency

        if isdelete:
            before_delete = unitofwork.ProcessAll(uow, self, True, True)
            before_delete.disabled = True
        else:
            after_save = unitofwork.ProcessAll(uow, self, False, True)
            after_save.disabled = True

        # check if the "child" side is part of the cycle

        if child_saves not in uow.cycles:
            # based on the current dependencies we use, the saves/
            # deletes should always be in the 'cycles' collection
            # together.   if this changes, we will have to break up
            # this method a bit more.
            assert child_deletes not in uow.cycles

            # child side is not part of the cycle, so we will link per-state
            # actions to the aggregate "saves", "deletes" actions
            child_actions = [
                (child_saves, False), (child_deletes, True)
            ]
            child_in_cycles = False
        else:
            child_in_cycles = True

        # check if the "parent" side is part of the cycle
        if not isdelete:
            parent_saves = unitofwork.SaveUpdateAll(
                uow,
                self.parent.base_mapper)
            parent_deletes = before_delete = None
            if parent_saves in uow.cycles:
                parent_in_cycles = True
        else:
            parent_deletes = unitofwork.DeleteAll(
                uow,
                self.parent.base_mapper)
            parent_saves = after_save = None
            if parent_deletes in uow.cycles:
                parent_in_cycles = True

        # now create actions /dependencies for each state.

        for state in states:
            # detect if there's anything changed or loaded
            # by a preprocessor on this state/attribute.   In the
            # case of deletes we may try to load missing items here as well.
            sum_ = state.manager[self.key].impl.get_all_pending(
                state, state.dict,
                self._passive_delete_flag
                if isdelete
                else attributes.PASSIVE_NO_INITIALIZE)

            if not sum_:
                continue

            if isdelete:
                before_delete = unitofwork.ProcessState(uow,
                                                        self, True, state)
                if parent_in_cycles:
                    parent_deletes = unitofwork.DeleteState(
                        uow,
                        state,
                        parent_base_mapper)
            else:
                after_save = unitofwork.ProcessState(uow, self, False, state)
                if parent_in_cycles:
                    parent_saves = unitofwork.SaveUpdateState(
                        uow,
                        state,
                        parent_base_mapper)

            if child_in_cycles:
                child_actions = []
                for child_state, child in sum_:
                    if child_state not in uow.states:
                        child_action = (None, None)
                    else:
                        (deleted, listonly) = uow.states[child_state]
                        if deleted:
                            child_action = (
                                unitofwork.DeleteState(
                                    uow, child_state,
                                    child_base_mapper),
                                True)
                        else:
                            child_action = (
                                unitofwork.SaveUpdateState(
                                    uow, child_state,
                                    child_base_mapper),
                                False)
                    child_actions.append(child_action)

            # establish dependencies between our possibly per-state
            # parent action and our possibly per-state child action.
            for child_action, childisdelete in child_actions:
                self.per_state_dependencies(uow, parent_saves,
                                            parent_deletes,
                                            child_action,
                                            after_save, before_delete,
                                            isdelete, childisdelete)
establish actions and dependencies related to a flush.
dataset/ETHPy150Open zzzeek/sqlalchemy/lib/sqlalchemy/orm/dependency.py/DependencyProcessor.per_state_flush_actions