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)
| 49 | |
| 50 | |
| 51 | def 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) |
no outgoing calls
no test coverage detected