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

Method get

lib/sqlalchemy/orm/attributes.py:1073–1116  ·  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

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