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

Function _parse_attr_argument

lib/sqlalchemy/orm/strategy_options.py:2366–2400  ·  view source on GitHub ↗

parse an attribute or wildcard argument to produce an :class:`._AbstractLoad` instance. This is used by the standalone loader strategy functions like ``joinedload()``, ``defer()``, etc. to produce :class:`_orm.Load` or :class:`._WildcardLoad` objects.

(
    attr: _AttrType,
)

Source from the content-addressed store, hash-verified

2364
2365
2366def _parse_attr_argument(
2367 attr: _AttrType,
2368) -> Tuple[InspectionAttr, _InternalEntityType[Any], MapperProperty[Any]]:
2369 """parse an attribute or wildcard argument to produce an
2370 :class:`._AbstractLoad` instance.
2371
2372 This is used by the standalone loader strategy functions like
2373 ``joinedload()``, ``defer()``, etc. to produce :class:`_orm.Load` or
2374 :class:`._WildcardLoad` objects.
2375
2376 """
2377 try:
2378 # TODO: need to figure out this None thing being returned by
2379 # inspect(), it should not have None as an option in most cases
2380 # if at all
2381 insp: InspectionAttr = inspect(attr) # type: ignore
2382 except sa_exc.NoInspectionAvailable as err:
2383 raise sa_exc.ArgumentError(
2384 "expected ORM mapped attribute for loader strategy argument"
2385 ) from err
2386
2387 lead_entity: _InternalEntityType[Any]
2388
2389 if insp_is_mapper_property(insp):
2390 lead_entity = insp.parent
2391 prop = insp
2392 elif insp_is_attribute(insp):
2393 lead_entity = insp.parent
2394 prop = insp.prop
2395 else:
2396 raise sa_exc.ArgumentError(
2397 "expected ORM mapped attribute for loader strategy argument"
2398 )
2399
2400 return insp, lead_entity, prop
2401
2402
2403def loader_unbound_fn(fn: _FN) -> _FN:

Callers 3

_init_pathMethod · 0.85
_generate_from_keysFunction · 0.85
load_onlyFunction · 0.85

Calls 3

inspectFunction · 0.90
insp_is_mapper_propertyFunction · 0.85
insp_is_attributeFunction · 0.85

Tested by

no test coverage detected