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)
| 401 | |
| 402 | |
| 403 | def 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) |
no test coverage detected