MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / add

Method add

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

Source from the content-addressed store, hash-verified

179 return existing
180
181 def add(self, state: InstanceState[Any]) -> bool:
182 key = state.key
183 assert key is not None
184 # inline of self.__contains__
185 if key in self._dict:
186 try:
187 existing_state = self._dict[key]
188 except KeyError:
189 # catch gc removed the key after we just checked for it
190 pass
191 else:
192 if existing_state is not state:
193 o = existing_state.obj()
194 if o is not None:
195 raise sa_exc.InvalidRequestError(
196 "Can't attach instance "
197 "%s; another instance with key %s is already "
198 "present in this session."
199 % (orm_util.state_str(state), state.key)
200 )
201 else:
202 return False
203 self._dict[key] = state
204 self._manage_incoming_state(state)
205 return True
206
207 def _add_unpresent(
208 self, state: InstanceState[Any], key: _IdentityKeyType[Any]

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected