MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / object_session

Function object_session

lib/sqlalchemy/orm/session.py:5450–5463  ·  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

5448
5449
5450def object_session(instance: object) -> Optional[Session]:
5451 """Return the :class:`.Session` to which the given instance belongs.
5452
5453 This is essentially the same as the :attr:`.InstanceState.session`
5454 accessor. See that attribute for details.
5455
5456 """
5457
5458 try:
5459 state = attributes.instance_state(instance)
5460 except exc.NO_STATE as err:
5461 raise exc.UnmappedInstanceError(instance) from err
5462 else:
5463 return _state_session(state)
5464
5465
5466_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