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