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

Function object_session

lib/sqlalchemy/orm/session.py:5288–5301  ·  view source on GitHub ↗

Return the :class:`.Session` to which the given instance belongs. This is essentially the same as the :attr:`.InstanceState.session` accessor. See that attribute for details.

(instance: object)

Source from the content-addressed store, hash-verified

5286
5287
5288def object_session(instance: object) -> Optional[Session]:
5289 """Return the :class:`.Session` to which the given instance belongs.
5290
5291 This is essentially the same as the :attr:`.InstanceState.session`
5292 accessor. See that attribute for details.
5293
5294 """
5295
5296 try:
5297 state = attributes.instance_state(instance)
5298 except exc.NO_STATE as err:
5299 raise exc.UnmappedInstanceError(instance) from err
5300 else:
5301 return _state_session(state)
5302
5303
5304_new_sessionid = util.counter()

Callers 9

eMethod · 0.90
evtMethod · 0.90
async_object_sessionFunction · 0.85
sessionMethod · 0.85
_generateMethod · 0.85
object_sessionMethod · 0.85

Calls 1

_state_sessionFunction · 0.85

Tested by 5

eMethod · 0.72
evtMethod · 0.72