MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / orm_pre_session_exec

Method orm_pre_session_exec

lib/sqlalchemy/orm/context.py:492–579  ·  view source on GitHub ↗
(
        cls,
        session,
        statement,
        params,
        execution_options,
        bind_arguments,
        is_pre_event,
    )

Source from the content-addressed store, hash-verified

490
491 @classmethod
492 def orm_pre_session_exec(
493 cls,
494 session,
495 statement,
496 params,
497 execution_options,
498 bind_arguments,
499 is_pre_event,
500 ):
501 # consume result-level load_options. These may have been set up
502 # in an ORMExecuteState hook
503 (
504 load_options,
505 execution_options,
506 ) = QueryContext.default_load_options.from_execution_options(
507 "_sa_orm_load_options",
508 {
509 "populate_existing",
510 "autoflush",
511 "yield_per",
512 "identity_token",
513 "sa_top_level_orm_context",
514 },
515 execution_options,
516 statement._execution_options,
517 )
518
519 # default execution options for ORM results:
520 # 1. _result_disable_adapt_to_context=True
521 # this will disable the ResultSetMetadata._adapt_to_context()
522 # step which we don't need, as we have result processors cached
523 # against the original SELECT statement before caching.
524
525 if "sa_top_level_orm_context" in execution_options:
526 ctx = execution_options["sa_top_level_orm_context"]
527 execution_options = ctx.query._execution_options.merge_with(
528 ctx.execution_options, execution_options
529 )
530
531 if not execution_options:
532 execution_options = _orm_load_exec_options
533 else:
534 execution_options = execution_options.union(_orm_load_exec_options)
535
536 # would have been placed here by legacy Query only
537 if load_options._yield_per:
538 execution_options = execution_options.union(
539 {"yield_per": load_options._yield_per}
540 )
541
542 if (
543 getattr(statement._compile_options, "_current_path", None)
544 and len(statement._compile_options._current_path) > 10
545 and execution_options.get("compiled_cache", True) is not None
546 ):
547 execution_options: util.immutabledict[str, Any] = (
548 execution_options.union(
549 {

Callers 1

_execute_internalMethod · 0.45

Calls 5

_autoflushMethod · 0.80
merge_withMethod · 0.45
unionMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected