MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / cascade_iterator

Method cascade_iterator

lib/sqlalchemy/orm/mapper.py:3929–4024  ·  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

3927 return self._subclass_load_via_in(self, self.base_mapper)
3928
3929 def cascade_iterator(
3930 self,
3931 type_: str,
3932 state: InstanceState[_O],
3933 halt_on: Optional[Callable[[InstanceState[Any]], bool]] = None,
3934 ) -> Iterator[
3935 Tuple[object, Mapper[Any], InstanceState[Any], _InstanceDict]
3936 ]:
3937 r"""Iterate each element and its mapper in an object graph,
3938 for all relationships that meet the given cascade rule.
3939
3940 :param type\_:
3941 The name of the cascade rule (i.e. ``"save-update"``, ``"delete"``,
3942 etc.).
3943
3944 .. note:: the ``"all"`` cascade is not accepted here. For a generic
3945 object traversal function, see :ref:`faq_walk_objects`.
3946
3947 :param state:
3948 The lead InstanceState. child items will be processed per
3949 the relationships defined for this object's mapper.
3950
3951 :return: the method yields individual object instances.
3952
3953 .. seealso::
3954
3955 :ref:`unitofwork_cascades`
3956
3957 :ref:`faq_walk_objects` - illustrates a generic function to
3958 traverse all objects without relying on cascades.
3959
3960 """
3961 visited_states: Set[InstanceState[Any]] = set()
3962 prp, mpp = object(), object()
3963
3964 assert state.mapper.isa(self)
3965
3966 # this is actually a recursive structure, fully typing it seems
3967 # a little too difficult for what it's worth here
3968 visitables: Deque[
3969 Tuple[
3970 Deque[Any],
3971 object,
3972 Optional[InstanceState[Any]],
3973 Optional[_InstanceDict],
3974 ]
3975 ]
3976
3977 visitables = deque(
3978 [(deque(state.mapper._props.values()), prp, state, state.dict)]
3979 )
3980
3981 while visitables:
3982 iterator, item_type, parent_state, parent_dict = visitables[-1]
3983 if not iterator:
3984 visitables.pop()
3985 continue
3986

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