MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _prepare_impl

Method _prepare_impl

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

Source from the content-addressed store, hash-verified

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

Callers 2

prepareMethod · 0.95
commitMethod · 0.95

Calls 10

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

Tested by

no test coverage detected