Look up the given key in the given session's identity map, check the object for expired state if found.
(
session: Session,
mapper: Mapper[_O],
key: _IdentityKeyType[_O],
passive: PassiveFlag,
)
| 456 | |
| 457 | |
| 458 | def get_from_identity( |
| 459 | session: Session, |
| 460 | mapper: Mapper[_O], |
| 461 | key: _IdentityKeyType[_O], |
| 462 | passive: PassiveFlag, |
| 463 | ) -> Union[LoaderCallableStatus, Optional[_O]]: |
| 464 | """Look up the given key in the given session's identity map, |
| 465 | check the object for expired state if found. |
| 466 | |
| 467 | """ |
| 468 | instance = session.identity_map.get(key) |
| 469 | if instance is not None: |
| 470 | state = attributes.instance_state(instance) |
| 471 | |
| 472 | if mapper.inherits and not state.mapper.isa(mapper): |
| 473 | return attributes.PASSIVE_CLASS_MISMATCH |
| 474 | |
| 475 | # expired - ensure it still exists |
| 476 | if state.expired: |
| 477 | if not passive & attributes.SQL_OK: |
| 478 | # TODO: no coverage here |
| 479 | return attributes.PASSIVE_NO_RESULT |
| 480 | elif not passive & attributes.RELATED_OBJECT_OK: |
| 481 | # this mode is used within a flush and the instance's |
| 482 | # expired state will be checked soon enough, if necessary. |
| 483 | # also used by immediateloader for a mutually-dependent |
| 484 | # o2m->m2m load, :ticket:`6301` |
| 485 | return instance |
| 486 | try: |
| 487 | state._load_expired(state, passive) |
| 488 | except orm_exc.ObjectDeletedError: |
| 489 | session._remove_newly_deleted([state]) |
| 490 | return None |
| 491 | return instance |
| 492 | else: |
| 493 | return None |
| 494 | |
| 495 | |
| 496 | def _load_on_ident( |
nothing calls this directly
no test coverage detected