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

Method flush

lib/sqlalchemy/orm/session.py:4323–4355  ·  view source on GitHub ↗

Flush all the object changes to the database. Writes out all pending object creations, deletions and modifications to the database as INSERTs, DELETEs, UPDATEs, etc. Operations are automatically ordered by the Session's unit of work dependency solver. Datab

(self, objects: Optional[Sequence[Any]] = None)

Source from the content-addressed store, hash-verified

4321 return state in self._new or self.identity_map.contains_state(state)
4322
4323 def flush(self, objects: Optional[Sequence[Any]] = None) -> None:
4324 """Flush all the object changes to the database.
4325
4326 Writes out all pending object creations, deletions and modifications
4327 to the database as INSERTs, DELETEs, UPDATEs, etc. Operations are
4328 automatically ordered by the Session's unit of work dependency
4329 solver.
4330
4331 Database operations will be issued in the current transactional
4332 context and do not affect the state of the transaction, unless an
4333 error occurs, in which case the entire transaction is rolled back.
4334 You may flush() as often as you like within a transaction to move
4335 changes from Python to the database's transaction buffer.
4336
4337 :param objects: Optional; restricts the flush operation to operate
4338 only on elements that are in the given collection.
4339
4340 This feature is for an extremely narrow set of use cases where
4341 particular objects may need to be operated upon before the
4342 full flush() occurs. It is not intended for general use.
4343
4344 """
4345
4346 if self._flushing:
4347 raise sa_exc.InvalidRequestError("Session is already flushing")
4348
4349 if self._is_clean():
4350 return
4351 try:
4352 self._flushing = True
4353 self._flush(objects)
4354 finally:
4355 self._flushing = False
4356
4357 def _flush_warning(self, method: Any) -> None:
4358 util.warn(

Calls 2

_is_cleanMethod · 0.95
_flushMethod · 0.95