MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _emit_lazyload

Method _emit_lazyload

lib/sqlalchemy/orm/strategies.py:1023–1174  ·  view source on GitHub ↗
(
        self,
        session,
        state,
        primary_key_identity,
        passive,
        loadopt,
        extra_criteria,
        extra_options,
        alternate_effective_path,
        execution_options,
    )

Source from the content-addressed store, hash-verified

1021
1022 @util.preload_module("sqlalchemy.orm.strategy_options")
1023 def _emit_lazyload(
1024 self,
1025 session,
1026 state,
1027 primary_key_identity,
1028 passive,
1029 loadopt,
1030 extra_criteria,
1031 extra_options,
1032 alternate_effective_path,
1033 execution_options,
1034 ):
1035 strategy_options = util.preloaded.orm_strategy_options
1036
1037 clauseelement = self.entity.__clause_element__()
1038 stmt = Select._create_raw_select(
1039 _raw_columns=[clauseelement],
1040 _propagate_attrs=clauseelement._propagate_attrs,
1041 _compile_options=_ORMCompileState.default_compile_options,
1042 )
1043 load_options = QueryContext.default_load_options
1044
1045 load_options += {
1046 "_invoke_all_eagers": False,
1047 "_lazy_loaded_from": state,
1048 }
1049
1050 if self.parent_property.secondary is not None:
1051 stmt = stmt.select_from(
1052 self.mapper, self.parent_property.secondary
1053 )
1054
1055 pending = not state.key
1056
1057 # don't autoflush on pending
1058 if pending or passive & attributes.NO_AUTOFLUSH:
1059 stmt._execution_options = util.immutabledict({"autoflush": False})
1060
1061 use_get = self.use_get
1062
1063 if state.load_options or (loadopt and loadopt._extra_criteria):
1064 if alternate_effective_path is None:
1065 effective_path = state.load_path[self.parent_property]
1066 else:
1067 effective_path = alternate_effective_path[self.parent_property]
1068
1069 opts = state.load_options
1070
1071 if loadopt and loadopt._extra_criteria:
1072 use_get = False
1073 opts += (
1074 orm_util.LoaderCriteriaOption(self.entity, extra_criteria),
1075 )
1076
1077 stmt._with_options = opts
1078 elif alternate_effective_path is None:
1079 # this path is used if there are not already any options
1080 # in the query, but an event may want to add them

Callers 1

_load_for_stateMethod · 0.95

Calls 14

_invoke_raise_loadMethod · 0.95
_generate_lazy_clauseMethod · 0.95
_create_raw_selectMethod · 0.80
_load_on_pk_identityMethod · 0.80
__clause_element__Method · 0.45
select_fromMethod · 0.45
merge_withMethod · 0.45
valuesMethod · 0.45
executeMethod · 0.45
allMethod · 0.45
scalarsMethod · 0.45

Tested by

no test coverage detected