MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _update_impl

Method _update_impl

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

Source from the content-addressed store, hash-verified

4313 self._after_attach(state, obj)
4314
4315 def _update_impl(
4316 self, state: InstanceState[Any], revert_deletion: bool = False
4317 ) -> None:
4318 if state.key is None:
4319 raise sa_exc.InvalidRequestError(
4320 "Instance '%s' is not persisted" % state_str(state)
4321 )
4322
4323 if state._deleted:
4324 if revert_deletion:
4325 if not state._attached:
4326 return
4327 del state._deleted
4328 else:
4329 raise sa_exc.InvalidRequestError(
4330 "Instance '%s' has been deleted. "
4331 "Use the make_transient() "
4332 "function to send this object back "
4333 "to the transient state." % state_str(state)
4334 )
4335
4336 obj = state.obj()
4337
4338 # check for late gc
4339 if obj is None:
4340 return
4341
4342 to_attach = self._before_attach(state, obj)
4343
4344 self._deleted.pop(state, None)
4345 if revert_deletion:
4346 self.identity_map.replace(state)
4347 else:
4348 self.identity_map.add(state)
4349
4350 if to_attach:
4351 self._after_attach(state, obj)
4352 elif revert_deletion:
4353 self.dispatch.deleted_to_persistent(self, state)
4354
4355 def _save_or_update_impl(self, state: InstanceState[Any]) -> None:
4356 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