Return an ORM result given a :class:`_engine.CursorResult` and :class:`.QueryContext`.
(
self,
result_proxy: CursorResult[Any],
context: Optional[QueryContext] = None,
)
| 3009 | "conjunction with Session.execute() instead.", |
| 3010 | ) |
| 3011 | def instances( |
| 3012 | self, |
| 3013 | result_proxy: CursorResult[Any], |
| 3014 | context: Optional[QueryContext] = None, |
| 3015 | ) -> Any: |
| 3016 | """Return an ORM result given a :class:`_engine.CursorResult` and |
| 3017 | :class:`.QueryContext`. |
| 3018 | |
| 3019 | """ |
| 3020 | if context is None: |
| 3021 | util.warn_deprecated( |
| 3022 | "Using the Query.instances() method without a context " |
| 3023 | "is deprecated and will be disallowed in a future release. " |
| 3024 | "Please make use of :meth:`_query.Query.from_statement` " |
| 3025 | "for linking ORM results to arbitrary select constructs.", |
| 3026 | version="1.4", |
| 3027 | ) |
| 3028 | compile_state = self._compile_state(for_statement=False) |
| 3029 | |
| 3030 | context = QueryContext( |
| 3031 | compile_state, |
| 3032 | compile_state.statement, |
| 3033 | compile_state.statement, |
| 3034 | self._params, |
| 3035 | self.session, |
| 3036 | self.load_options, |
| 3037 | ) |
| 3038 | |
| 3039 | result = loading.instances(result_proxy, context) |
| 3040 | |
| 3041 | # legacy: automatically set scalars, unique |
| 3042 | if result._attributes.get("is_single_entity", False): |
| 3043 | result = result.scalars() # type: ignore |
| 3044 | |
| 3045 | if result._attributes.get("filtered", False): |
| 3046 | result = result.unique() |
| 3047 | |
| 3048 | # TODO: isn't this supposed to be a list? |
| 3049 | return result |
| 3050 | |
| 3051 | @util.became_legacy_20( |
| 3052 | ":meth:`_orm.Query.merge_result`", |
no test coverage detected