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

Method _update_impl

lib/sqlalchemy/orm/session.py:4159–4197  ·  view source on GitHub ↗
(
        self, state: InstanceState[Any], revert_deletion: bool = False
    )

Source from the content-addressed store, hash-verified

4157 self._after_attach(state, obj)
4158
4159 def _update_impl(
4160 self, state: InstanceState[Any], revert_deletion: bool = False
4161 ) -> None:
4162 if state.key is None:
4163 raise sa_exc.InvalidRequestError(
4164 "Instance '%s' is not persisted" % state_str(state)
4165 )
4166
4167 if state._deleted:
4168 if revert_deletion:
4169 if not state._attached:
4170 return
4171 del state._deleted
4172 else:
4173 raise sa_exc.InvalidRequestError(
4174 "Instance '%s' has been deleted. "
4175 "Use the make_transient() "
4176 "function to send this object back "
4177 "to the transient state." % state_str(state)
4178 )
4179
4180 obj = state.obj()
4181
4182 # check for late gc
4183 if obj is None:
4184 return
4185
4186 to_attach = self._before_attach(state, obj)
4187
4188 self._deleted.pop(state, None)
4189 if revert_deletion:
4190 self.identity_map.replace(state)
4191 else:
4192 self.identity_map.add(state)
4193
4194 if to_attach:
4195 self._after_attach(state, obj)
4196 elif revert_deletion:
4197 self.dispatch.deleted_to_persistent(self, state)
4198
4199 def _save_or_update_impl(self, state: InstanceState[Any]) -> None:
4200 if state.key is None:

Callers 3

_mergeMethod · 0.95
_save_or_update_implMethod · 0.95
_restore_snapshotMethod · 0.80

Calls 7

_before_attachMethod · 0.95
_after_attachMethod · 0.95
state_strFunction · 0.85
deleted_to_persistentMethod · 0.80
popMethod · 0.45
replaceMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected