(
self,
session,
state,
primary_key_identity,
passive,
loadopt,
extra_criteria,
extra_options,
alternate_effective_path,
execution_options,
)
| 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 |
no test coverage detected