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

Method _before_attach

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

Source from the content-addressed store, hash-verified

4268 self._after_attach(state, obj)
4269
4270 def _before_attach(self, state: InstanceState[Any], obj: object) -> bool:
4271 self._autobegin_t()
4272
4273 if state.session_id == self.hash_key:
4274 return False
4275
4276 if state.session_id and state.session_id in _sessions:
4277 raise sa_exc.InvalidRequestError(
4278 "Object '%s' is already attached to session '%s' "
4279 "(this is '%s')"
4280 % (state_str(state), state.session_id, self.hash_key)
4281 )
4282
4283 self.dispatch.before_attach(self, state)
4284
4285 return True
4286
4287 def _after_attach(self, state: InstanceState[Any], obj: object) -> None:
4288 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