Return an ORM result given a :class:`_engine.CursorResult` and :class:`.QueryContext`.
(
self,
result_proxy: CursorResult[Any],
context: Optional[QueryContext] = None,
)
| 2955 | "conjunction with Session.execute() instead.", |
| 2956 | ) |
| 2957 | def instances( |
| 2958 | self, |
| 2959 | result_proxy: CursorResult[Any], |
| 2960 | context: Optional[QueryContext] = None, |
| 2961 | ) -> Any: |
| 2962 | """Return an ORM result given a :class:`_engine.CursorResult` and |
| 2963 | :class:`.QueryContext`. |
| 2964 | |
| 2965 | """ |
| 2966 | if context is None: |
| 2967 | util.warn_deprecated( |
| 2968 | "Using the Query.instances() method without a context " |
| 2969 | "is deprecated and will be disallowed in a future release. " |
| 2970 | "Please make use of :meth:`_query.Query.from_statement` " |
| 2971 | "for linking ORM results to arbitrary select constructs.", |
| 2972 | version="1.4", |
| 2973 | ) |
| 2974 | compile_state = self._compile_state(for_statement=False) |
| 2975 | |
| 2976 | context = QueryContext( |
| 2977 | compile_state, |
| 2978 | compile_state.statement, |
| 2979 | compile_state.statement, |
| 2980 | self._params, |
| 2981 | self.session, |
| 2982 | self.load_options, |
| 2983 | ) |
| 2984 | |
| 2985 | result = loading.instances(result_proxy, context) |
| 2986 | |
| 2987 | # legacy: automatically set scalars, unique |
| 2988 | if result._attributes.get("is_single_entity", False): |
| 2989 | result = result.scalars() # type: ignore |
| 2990 | |
| 2991 | if result._attributes.get("filtered", False): |
| 2992 | result = result.unique() |
| 2993 | |
| 2994 | # TODO: isn't this supposed to be a list? |
| 2995 | return result |
| 2996 | |
| 2997 | @util.became_legacy_20( |
| 2998 | ":meth:`_orm.Query.merge_result`", |
no test coverage detected