MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / cascade_iterator

Method cascade_iterator

lib/sqlalchemy/orm/mapper.py:3901–3996  ·  view source on GitHub ↗

r"""Iterate each element and its mapper in an object graph, for all relationships that meet the given cascade rule. :param type\_: The name of the cascade rule (i.e. ``"save-update"``, ``"delete"``, etc.). .. note:: the ``"all"`` cascade is not accept

(
        self,
        type_: str,
        state: InstanceState[_O],
        halt_on: Optional[Callable[[InstanceState[Any]], bool]] = None,
    )

Source from the content-addressed store, hash-verified

3899 return self._subclass_load_via_in(self, self.base_mapper)
3900
3901 def cascade_iterator(
3902 self,
3903 type_: str,
3904 state: InstanceState[_O],
3905 halt_on: Optional[Callable[[InstanceState[Any]], bool]] = None,
3906 ) -> Iterator[
3907 Tuple[object, Mapper[Any], InstanceState[Any], _InstanceDict]
3908 ]:
3909 r"""Iterate each element and its mapper in an object graph,
3910 for all relationships that meet the given cascade rule.
3911
3912 :param type\_:
3913 The name of the cascade rule (i.e. ``"save-update"``, ``"delete"``,
3914 etc.).
3915
3916 .. note:: the ``"all"`` cascade is not accepted here. For a generic
3917 object traversal function, see :ref:`faq_walk_objects`.
3918
3919 :param state:
3920 The lead InstanceState. child items will be processed per
3921 the relationships defined for this object's mapper.
3922
3923 :return: the method yields individual object instances.
3924
3925 .. seealso::
3926
3927 :ref:`unitofwork_cascades`
3928
3929 :ref:`faq_walk_objects` - illustrates a generic function to
3930 traverse all objects without relying on cascades.
3931
3932 """
3933 visited_states: Set[InstanceState[Any]] = set()
3934 prp, mpp = object(), object()
3935
3936 assert state.mapper.isa(self)
3937
3938 # this is actually a recursive structure, fully typing it seems
3939 # a little too difficult for what it's worth here
3940 visitables: Deque[
3941 Tuple[
3942 Deque[Any],
3943 object,
3944 Optional[InstanceState[Any]],
3945 Optional[_InstanceDict],
3946 ]
3947 ]
3948
3949 visitables = deque(
3950 [(deque(state.mapper._props.values()), prp, state, state.dict)]
3951 )
3952
3953 while visitables:
3954 iterator, item_type, parent_state, parent_dict = visitables[-1]
3955 if not iterator:
3956 visitables.pop()
3957 continue
3958

Callers 9

presort_savesMethod · 0.45
presort_deletesMethod · 0.45
presort_savesMethod · 0.45
presort_savesMethod · 0.45
_expire_stateMethod · 0.45
expungeMethod · 0.45
_save_or_update_stateMethod · 0.45
_delete_implMethod · 0.45

Calls 4

isaMethod · 0.80
valuesMethod · 0.45
popMethod · 0.45
appendMethod · 0.45

Tested by 1