(
self,
state: InstanceState[_O],
state_dict: _InstanceDict,
*,
options: Optional[Sequence[ORMOption]] = None,
load: bool,
_recursive: Dict[Any, object],
_resolve_conflict_map: Dict[_IdentityKeyType[Any], object],
)
| 4132 | ] |
| 4133 | |
| 4134 | def _merge( |
| 4135 | self, |
| 4136 | state: InstanceState[_O], |
| 4137 | state_dict: _InstanceDict, |
| 4138 | *, |
| 4139 | options: Optional[Sequence[ORMOption]] = None, |
| 4140 | load: bool, |
| 4141 | _recursive: Dict[Any, object], |
| 4142 | _resolve_conflict_map: Dict[_IdentityKeyType[Any], object], |
| 4143 | ) -> _O: |
| 4144 | mapper: Mapper[_O] = _state_mapper(state) |
| 4145 | if state in _recursive: |
| 4146 | return cast(_O, _recursive[state]) |
| 4147 | |
| 4148 | new_instance = False |
| 4149 | key = state.key |
| 4150 | |
| 4151 | merged: Optional[_O] |
| 4152 | |
| 4153 | if key is None: |
| 4154 | if state in self._new: |
| 4155 | util.warn( |
| 4156 | "Instance %s is already pending in this Session yet is " |
| 4157 | "being merged again; this is probably not what you want " |
| 4158 | "to do" % state_str(state) |
| 4159 | ) |
| 4160 | |
| 4161 | if not load: |
| 4162 | raise sa_exc.InvalidRequestError( |
| 4163 | "merge() with load=False option does not support " |
| 4164 | "objects transient (i.e. unpersisted) objects. flush() " |
| 4165 | "all changes on mapped instances before merging with " |
| 4166 | "load=False." |
| 4167 | ) |
| 4168 | key = mapper._identity_key_from_state(state) |
| 4169 | key_is_persistent = LoaderCallableStatus.NEVER_SET not in key[ |
| 4170 | 1 |
| 4171 | ] and ( |
| 4172 | not _none_set.intersection(key[1]) |
| 4173 | or ( |
| 4174 | mapper.allow_partial_pks |
| 4175 | and not _none_set.issuperset(key[1]) |
| 4176 | ) |
| 4177 | ) |
| 4178 | else: |
| 4179 | key_is_persistent = True |
| 4180 | |
| 4181 | merged = self.identity_map.get(key) |
| 4182 | |
| 4183 | if merged is None: |
| 4184 | if key_is_persistent and key in _resolve_conflict_map: |
| 4185 | merged = cast(_O, _resolve_conflict_map[key]) |
| 4186 | |
| 4187 | elif not load: |
| 4188 | if state.modified: |
| 4189 | raise sa_exc.InvalidRequestError( |
| 4190 | "merge() with load=False option does not support " |
| 4191 | "objects marked as 'dirty'. flush() all changes on " |
no test coverage detected