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

Function object_state

lib/sqlalchemy/orm/base.py:403–424  ·  view source on GitHub ↗

Given an object, return the :class:`.InstanceState` associated with the object. Raises :class:`sqlalchemy.orm.exc.UnmappedInstanceError` if no mapping is configured. Equivalent functionality is available via the :func:`_sa.inspect` function as:: inspect(instance)

(instance: _T)

Source from the content-addressed store, hash-verified

401
402
403def object_state(instance: _T) -> InstanceState[_T]:
404 """Given an object, return the :class:`.InstanceState`
405 associated with the object.
406
407 Raises :class:`sqlalchemy.orm.exc.UnmappedInstanceError`
408 if no mapping is configured.
409
410 Equivalent functionality is available via the :func:`_sa.inspect`
411 function as::
412
413 inspect(instance)
414
415 Using the inspection system will raise
416 :class:`sqlalchemy.exc.NoInspectionAvailable` if the instance is
417 not part of a mapping.
418
419 """
420 state = _inspect_mapped_object(instance)
421 if state is None:
422 raise exc.UnmappedInstanceError(instance)
423 else:
424 return state
425
426
427@inspection._inspects(object)

Callers 2

object_mapperFunction · 0.85
is_modifiedMethod · 0.85

Calls 1

_inspect_mapped_objectFunction · 0.85

Tested by

no test coverage detected