MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / _process_key_switches

Method _process_key_switches

lib/sqlalchemy/orm/dependency.py:944–979  ·  view source on GitHub ↗
(self, deplist, uowcommit)

Source from the content-addressed store, hash-verified

942 return switched
943
944 def _process_key_switches(self, deplist, uowcommit):
945 switchers = self._key_switchers(uowcommit, deplist)
946 if switchers:
947 # if primary key values have actually changed somewhere, perform
948 # a linear search through the UOW in search of a parent.
949 for state in uowcommit.session.identity_map.all_states():
950 if not issubclass(state.class_, self.parent.class_):
951 continue
952 dict_ = state.dict
953 related = state.get_impl(self.key).get(
954 state, dict_, passive=self._passive_update_flag
955 )
956 if (
957 related is not attributes.PASSIVE_NO_RESULT
958 and related is not None
959 ):
960 if self.prop.uselist:
961 if not related:
962 continue
963 related_obj = related[0]
964 else:
965 related_obj = related
966 related_state = attributes.instance_state(related_obj)
967 if related_state in switchers:
968 uowcommit.register_object(
969 state, False, self.passive_updates
970 )
971 sync._populate(
972 related_state,
973 self.mapper,
974 state,
975 self.parent,
976 self.prop.synchronize_pairs,
977 uowcommit,
978 self.passive_updates,
979 )
980
981 def _pks_changed(self, uowcommit, state):
982 return bool(state.key) and sync._source_modified(

Callers 2

presort_savesMethod · 0.95
process_savesMethod · 0.95

Calls 5

_key_switchersMethod · 0.95
register_objectMethod · 0.80
all_statesMethod · 0.45
getMethod · 0.45
get_implMethod · 0.45

Tested by

no test coverage detected