MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / _DetectKeySwitch

Class _DetectKeySwitch

lib/sqlalchemy/orm/dependency.py:870–984  ·  view source on GitHub ↗

For many-to-one relationships with no one-to-many backref, searches for parents through the unit of work when a primary key has changed and updates them. Theoretically, this approach could be expanded to support transparent deletion of objects referenced via many-to-one as well, alt

Source from the content-addressed store, hash-verified

868
869
870class _DetectKeySwitch(_DependencyProcessor):
871 """For many-to-one relationships with no one-to-many backref,
872 searches for parents through the unit of work when a primary
873 key has changed and updates them.
874
875 Theoretically, this approach could be expanded to support transparent
876 deletion of objects referenced via many-to-one as well, although
877 the current attribute system doesn't do enough bookkeeping for this
878 to be efficient.
879
880 """
881
882 def per_property_preprocessors(self, uow):
883 if self.prop._reverse_property:
884 if self.passive_updates:
885 return
886 else:
887 if False in (
888 prop.passive_updates
889 for prop in self.prop._reverse_property
890 ):
891 return
892
893 uow.register_preprocessor(self, False)
894
895 def per_property_flush_actions(self, uow):
896 parent_saves = unitofwork._SaveUpdateAll(uow, self.parent.base_mapper)
897 after_save = unitofwork._ProcessAll(uow, self, False, False)
898 uow.dependencies.update([(parent_saves, after_save)])
899
900 def per_state_flush_actions(self, uow, states, isdelete):
901 pass
902
903 def presort_deletes(self, uowcommit, states):
904 pass
905
906 def presort_saves(self, uow, states):
907 if not self.passive_updates:
908 # for non-passive updates, register in the preprocess stage
909 # so that mapper save_obj() gets a hold of changes
910 self._process_key_switches(states, uow)
911
912 def prop_has_changes(self, uow, states, isdelete):
913 if not isdelete and self.passive_updates:
914 d = self._key_switchers(uow, states)
915 return bool(d)
916
917 return False
918
919 def process_deletes(self, uowcommit, states):
920 assert False
921
922 def process_saves(self, uowcommit, states):
923 # for passive updates, register objects in the process stage
924 # so that we avoid ManyToOneDP's registering the object without
925 # the listonly flag in its own preprocess stage (results in UPDATE)
926 # statements being emitted
927 assert self.passive_updates

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected