MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _entity_descriptor

Function _entity_descriptor

lib/sqlalchemy/orm/base.py:485–509  ·  view source on GitHub ↗

Return a class attribute given an entity and string name. May return :class:`.InstrumentedAttribute` or user-defined attribute.

(entity: _EntityType[Any], key: str)

Source from the content-addressed store, hash-verified

483
484@no_type_check
485def _entity_descriptor(entity: _EntityType[Any], key: str) -> Any:
486 """Return a class attribute given an entity and string name.
487
488 May return :class:`.InstrumentedAttribute` or user-defined
489 attribute.
490
491 """
492 insp = inspection.inspect(entity)
493 if insp.is_selectable:
494 description = entity
495 entity = insp.c
496 elif insp.is_aliased_class:
497 entity = insp.entity
498 description = entity
499 elif hasattr(insp, "mapper"):
500 description = entity = insp.mapper.class_
501 else:
502 description = entity
503
504 try:
505 return getattr(entity, key)
506 except AttributeError as err:
507 raise sa_exc.InvalidRequestError(
508 "Entity '%s' has no property '%s'" % (description, key)
509 ) from err
510
511
512if TYPE_CHECKING:

Callers 1

Calls

no outgoing calls

Tested by 1