Merge a :class:`_engine.FrozenResult` back into a :class:`_orm.Session`, returning a new :class:`_engine.Result` object with :term:`persistent` objects. See the section :ref:`do_orm_execute_re_executing` for an example. .. seealso:: :ref:`do_orm_execute_re_executing`
(session, statement, frozen_result, load=True)
| 311 | |
| 312 | @util.preload_module("sqlalchemy.orm.context") |
| 313 | def merge_frozen_result(session, statement, frozen_result, load=True): |
| 314 | """Merge a :class:`_engine.FrozenResult` back into a :class:`_orm.Session`, |
| 315 | returning a new :class:`_engine.Result` object with :term:`persistent` |
| 316 | objects. |
| 317 | |
| 318 | See the section :ref:`do_orm_execute_re_executing` for an example. |
| 319 | |
| 320 | .. seealso:: |
| 321 | |
| 322 | :ref:`do_orm_execute_re_executing` |
| 323 | |
| 324 | :meth:`_engine.Result.freeze` |
| 325 | |
| 326 | :class:`_engine.FrozenResult` |
| 327 | |
| 328 | """ |
| 329 | querycontext = util.preloaded.orm_context |
| 330 | |
| 331 | if load: |
| 332 | # flush current contents if we expect to load data |
| 333 | session._autoflush() |
| 334 | |
| 335 | ctx = querycontext._ORMSelectCompileState._create_entities_collection( |
| 336 | statement, legacy=False |
| 337 | ) |
| 338 | |
| 339 | with session.no_autoflush: |
| 340 | mapped_entities = [ |
| 341 | i |
| 342 | for i, e in enumerate(ctx._entities) |
| 343 | if isinstance(e, querycontext._MapperEntity) |
| 344 | ] |
| 345 | keys = [ent._label_name for ent in ctx._entities] |
| 346 | |
| 347 | keyed_tuple = result_tuple( |
| 348 | keys, [ent._extra_entities for ent in ctx._entities] |
| 349 | ) |
| 350 | |
| 351 | result = [] |
| 352 | for newrow in frozen_result._rewrite_rows(): |
| 353 | for i in mapped_entities: |
| 354 | if newrow[i] is not None: |
| 355 | newrow[i] = session._merge( |
| 356 | attributes.instance_state(newrow[i]), |
| 357 | attributes.instance_dict(newrow[i]), |
| 358 | load=load, |
| 359 | _recursive={}, |
| 360 | _resolve_conflict_map={}, |
| 361 | ) |
| 362 | |
| 363 | result.append(keyed_tuple(newrow)) |
| 364 | |
| 365 | return frozen_result.with_new_rows(result) |
| 366 | |
| 367 | |
| 368 | @util.became_legacy_20( |
nothing calls this directly
no test coverage detected