MCPcopy
hub / github.com/ormar-orm/ormar / extract_access_chains

Function extract_access_chains

ormar/queryset/utils.py:51–75  ·  view source on GitHub ↗

Unwrap ``FieldAccessor`` inputs (or lists that contain them) into their underlying dunder-path strings so downstream parsers see a uniform shape. Anything that isn't an accessor (or list of accessors) is returned unchanged — sets, tuples, dicts, and plain strings all pass through.

(value: Any)

Source from the content-addressed store, hash-verified

49
50
51def extract_access_chains(value: Any) -> Any:
52 """
53 Unwrap ``FieldAccessor`` inputs (or lists that contain them) into their
54 underlying dunder-path strings so downstream parsers see a uniform shape.
55 Anything that isn't an accessor (or list of accessors) is returned
56 unchanged — sets, tuples, dicts, and plain strings all pass through.
57
58 :param value: user input for a relation-spec method (``select_related``,
59 ``prefetch_related``, ``flatten_fields``)
60 :type value: Any
61 :return: a dunder string, a list with each accessor replaced by its chain,
62 or the original value unchanged
63 :rtype: Any
64 """
65 # Late import to avoid circular dependency with queryset package.
66 from ormar.queryset.field_accessor import FieldAccessor
67
68 if isinstance(value, FieldAccessor):
69 return [value._access_chain]
70 if isinstance(value, list):
71 return [
72 item._access_chain if isinstance(item, FieldAccessor) else item
73 for item in value
74 ]
75 return value
76
77
78@dataclass(frozen=True)

Callers 4

select_relatedMethod · 0.90
prefetch_relatedMethod · 0.90
flatten_fieldsMethod · 0.90
_resolve_flatten_mapMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected