MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _before_attach

Method _before_attach

lib/sqlalchemy/orm/session.py:4426–4441  ·  view source on GitHub ↗
(self, state: InstanceState[Any], obj: object)

Source from the content-addressed store, hash-verified

4424 self._after_attach(state, obj)
4425
4426 def _before_attach(self, state: InstanceState[Any], obj: object) -> bool:
4427 self._autobegin_t()
4428
4429 if state.session_id == self.hash_key:
4430 return False
4431
4432 if state.session_id and state.session_id in _sessions:
4433 raise sa_exc.InvalidRequestError(
4434 "Object '%s' is already attached to session '%s' "
4435 "(this is '%s')"
4436 % (state_str(state), state.session_id, self.hash_key)
4437 )
4438
4439 self.dispatch.before_attach(self, state)
4440
4441 return True
4442
4443 def _after_attach(self, state: InstanceState[Any], obj: object) -> None:
4444 state.session_id = self.hash_key

Callers 4

_delete_implMethod · 0.95
_save_implMethod · 0.95
_update_implMethod · 0.95

Calls 3

_autobegin_tMethod · 0.95
state_strFunction · 0.85
before_attachMethod · 0.45

Tested by

no test coverage detected