MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / set

Method set

lib/sqlalchemy/ext/associationproxy.py:902–928  ·  view source on GitHub ↗
(self, obj: Any, values: _T)

Source from the content-addressed store, hash-verified

900 return proxy
901
902 def set(self, obj: Any, values: _T) -> None:
903 if self.scalar:
904 creator = cast(
905 "_PlainCreatorProtocol[_T]",
906 (
907 self.parent.creator
908 if self.parent.creator
909 else self.target_class
910 ),
911 )
912 target = getattr(obj, self.target_collection)
913 if target is None:
914 if (
915 values is None
916 and not self.parent.create_on_none_assignment
917 ):
918 return
919 setattr(obj, self.target_collection, creator(values))
920 else:
921 self._scalar_set(target, values)
922 if values is None and self.parent.cascade_scalar_deletes:
923 setattr(obj, self.target_collection, None)
924 else:
925 proxy = self.get(obj)
926 assert self.collection_class is not None
927 if proxy is not values:
928 proxy._bulk_replace(self, values)
929
930 def delete(self, obj: Any) -> None:
931 if self.owning_class is None:

Callers 2

__set__Method · 0.45
__call__Method · 0.45

Calls 4

getMethod · 0.95
creatorFunction · 0.85
castFunction · 0.50
_bulk_replaceMethod · 0.45

Tested by

no test coverage detected