Return a :class:`.Result` given an ORM query context. :param cursor: a :class:`.CursorResult`, generated by a statement which came from :class:`.ORMCompileState` :param context: a :class:`.QueryContext` object :return: a :class:`.Result` object representing ORM results .. ve
(cursor: CursorResult[Any], context: QueryContext)
| 77 | |
| 78 | |
| 79 | def instances(cursor: CursorResult[Any], context: QueryContext) -> Result[Any]: |
| 80 | """Return a :class:`.Result` given an ORM query context. |
| 81 | |
| 82 | :param cursor: a :class:`.CursorResult`, generated by a statement |
| 83 | which came from :class:`.ORMCompileState` |
| 84 | |
| 85 | :param context: a :class:`.QueryContext` object |
| 86 | |
| 87 | :return: a :class:`.Result` object representing ORM results |
| 88 | |
| 89 | .. versionchanged:: 1.4 The instances() function now uses |
| 90 | :class:`.Result` objects and has an all new interface. |
| 91 | |
| 92 | """ |
| 93 | |
| 94 | context.runid = _new_runid() |
| 95 | |
| 96 | if context.top_level_context: |
| 97 | is_top_level = False |
| 98 | context.post_load_paths = context.top_level_context.post_load_paths |
| 99 | else: |
| 100 | is_top_level = True |
| 101 | context.post_load_paths = {} |
| 102 | |
| 103 | compile_state = context.compile_state |
| 104 | filtered = compile_state._has_mapper_entities |
| 105 | single_entity = ( |
| 106 | not context.load_options._only_return_tuples |
| 107 | and len(compile_state._entities) == 1 |
| 108 | and compile_state._entities[0].supports_single_entity |
| 109 | ) |
| 110 | |
| 111 | try: |
| 112 | process, labels, extra = list( |
| 113 | zip( |
| 114 | *[ |
| 115 | query_entity.row_processor(context, cursor) |
| 116 | for query_entity in context.compile_state._entities |
| 117 | ] |
| 118 | ) |
| 119 | ) |
| 120 | |
| 121 | if context.yield_per and ( |
| 122 | context.loaders_require_buffering |
| 123 | or context.loaders_require_uniquing |
| 124 | ): |
| 125 | raise sa_exc.InvalidRequestError( |
| 126 | "Can't use yield_per with eager loaders that require uniquing " |
| 127 | "or row buffering, e.g. joinedload() against collections " |
| 128 | "or subqueryload(). Consider the selectinload() strategy " |
| 129 | "for better flexibility in loading objects." |
| 130 | ) |
| 131 | |
| 132 | except Exception: |
| 133 | with util.safe_reraise(): |
| 134 | cursor.close() |
| 135 | |
| 136 | def _no_unique(entry): |
nothing calls this directly
no test coverage detected