MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _prepare_impl

Method _prepare_impl

lib/sqlalchemy/orm/session.py:1276–1307  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1274 (SessionTransactionState.ACTIVE,), SessionTransactionState.PREPARED
1275 )
1276 def _prepare_impl(self) -> None:
1277 if self._parent is None or self.nested:
1278 self.session.dispatch.before_commit(self.session)
1279
1280 stx = self.session._transaction
1281 assert stx is not None
1282 if stx is not self:
1283 for subtransaction in stx._iterate_self_and_parents(upto=self):
1284 subtransaction.commit()
1285
1286 if not self.session._flushing:
1287 for _flush_guard in range(100):
1288 if self.session._is_clean():
1289 break
1290 self.session.flush()
1291 else:
1292 raise exc.FlushError(
1293 "Over 100 subsequent flushes have occurred within "
1294 "session.commit() - is an after_flush() hook "
1295 "creating new objects?"
1296 )
1297
1298 if self._parent is None and self.session.twophase:
1299 try:
1300 for t in set(self._connections.values()):
1301 cast("TwoPhaseTransaction", t[1]).prepare()
1302 except:
1303 with util.safe_reraise():
1304 with self._expect_state(SessionTransactionState.CLOSED):
1305 self.rollback()
1306
1307 self._state = SessionTransactionState.PREPARED
1308
1309 @_StateChange.declare_states(
1310 (SessionTransactionState.ACTIVE, SessionTransactionState.PREPARED),

Callers 2

prepareMethod · 0.95
commitMethod · 0.95

Calls 10

rollbackMethod · 0.95
castFunction · 0.85
before_commitMethod · 0.80
_is_cleanMethod · 0.80
_expect_stateMethod · 0.80
commitMethod · 0.45
flushMethod · 0.45
valuesMethod · 0.45
prepareMethod · 0.45

Tested by

no test coverage detected