MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / replace

Method replace

lib/sqlalchemy/orm/identity.py:159–179  ·  view source on GitHub ↗
(
        self, state: InstanceState[Any]
    )

Source from the content-addressed store, hash-verified

157 return False
158
159 def replace(
160 self, state: InstanceState[Any]
161 ) -> Optional[InstanceState[Any]]:
162 assert state.key is not None
163 if state.key in self._dict:
164 try:
165 existing = existing_non_none = self._dict[state.key]
166 except KeyError:
167 # catch gc removed the key after we just checked for it
168 existing = None
169 else:
170 if existing_non_none is not state:
171 self._manage_removed_state(existing_non_none)
172 else:
173 return None
174 else:
175 existing = None
176
177 self._dict[state.key] = state
178 self._manage_incoming_state(state)
179 return existing
180
181 def add(self, state: InstanceState[Any]) -> bool:
182 key = state.key

Callers

nothing calls this directly

Calls 2

_manage_removed_stateMethod · 0.80

Tested by

no test coverage detected