MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / get

Method get

lib/sqlalchemy/orm/attributes.py:1068–1111  ·  view source on GitHub ↗

Retrieve a value from the given object. If a callable is assembled on this object's attribute, and passive is False, the callable will be executed and the resulting value will be set as the new value for this attribute.

(
        self,
        state: InstanceState[Any],
        dict_: _InstanceDict,
        passive: PassiveFlag = PASSIVE_OFF,
    )

Source from the content-addressed store, hash-verified

1066 raise NotImplementedError()
1067
1068 def get(
1069 self,
1070 state: InstanceState[Any],
1071 dict_: _InstanceDict,
1072 passive: PassiveFlag = PASSIVE_OFF,
1073 ) -> Any:
1074 """Retrieve a value from the given object.
1075 If a callable is assembled on this object's attribute, and
1076 passive is False, the callable will be executed and the
1077 resulting value will be set as the new value for this attribute.
1078 """
1079 if self.key in dict_:
1080 return dict_[self.key]
1081 else:
1082 # if history present, don't load
1083 key = self.key
1084 if (
1085 key not in state.committed_state
1086 or state.committed_state[key] is NO_VALUE
1087 ):
1088 if not passive & CALLABLES_OK:
1089 return PASSIVE_NO_RESULT
1090
1091 value = self._fire_loader_callables(state, key, passive)
1092
1093 if value is PASSIVE_NO_RESULT or value is NO_VALUE:
1094 return value
1095 elif value is ATTR_WAS_SET:
1096 try:
1097 return dict_[key]
1098 except KeyError as err:
1099 # TODO: no test coverage here.
1100 raise KeyError(
1101 "Deferred loader for attribute "
1102 "%r failed to populate "
1103 "correctly" % key
1104 ) from err
1105 elif value is not ATTR_EMPTY:
1106 return self.set_committed_value(state, dict_, value)
1107
1108 if not passive & INIT_OK:
1109 return NO_VALUE
1110 else:
1111 return self._default_value(state, dict_)
1112
1113 def _fire_loader_callables(
1114 self, state: InstanceState[Any], key: str, passive: PassiveFlag

Callers 15

get_committed_valueMethod · 0.95
__get__Method · 0.45
hasparentMethod · 0.45
deleteMethod · 0.45
get_historyMethod · 0.45
setMethod · 0.45
deleteMethod · 0.45
get_historyMethod · 0.45
get_all_pendingMethod · 0.45
setMethod · 0.45
get_historyMethod · 0.45
setMethod · 0.45

Calls 3

set_committed_valueMethod · 0.95
_default_valueMethod · 0.95

Tested by

no test coverage detected