MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _parse_attr_argument

Function _parse_attr_argument

lib/sqlalchemy/orm/strategy_options.py:2360–2394  ·  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

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