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

Method commit

lib/sqlalchemy/orm/session.py:1999–2035  ·  view source on GitHub ↗

Flush pending changes and commit the current transaction. When the COMMIT operation is complete, all objects are fully :term:`expired`, erasing their internal contents, which will be automatically re-loaded when the objects are next accessed. In the interim, these ob

(self)

Source from the content-addressed store, hash-verified

1997 self._transaction.rollback(_to_root=True)
1998
1999 def commit(self) -> None:
2000 """Flush pending changes and commit the current transaction.
2001
2002 When the COMMIT operation is complete, all objects are fully
2003 :term:`expired`, erasing their internal contents, which will be
2004 automatically re-loaded when the objects are next accessed. In the
2005 interim, these objects are in an expired state and will not function if
2006 they are :term:`detached` from the :class:`.Session`. Additionally,
2007 this re-load operation is not supported when using asyncio-oriented
2008 APIs. The :paramref:`.Session.expire_on_commit` parameter may be used
2009 to disable this behavior.
2010
2011 When there is no transaction in place for the :class:`.Session`,
2012 indicating that no operations were invoked on this :class:`.Session`
2013 since the previous call to :meth:`.Session.commit`, the method will
2014 begin and commit an internal-only "logical" transaction, that does not
2015 normally affect the database unless pending flush changes were
2016 detected, but will still invoke event handlers and object expiration
2017 rules.
2018
2019 The outermost database transaction is committed unconditionally,
2020 automatically releasing any SAVEPOINTs in effect.
2021
2022 .. seealso::
2023
2024 :ref:`session_committing`
2025
2026 :ref:`unitofwork_transaction`
2027
2028 :ref:`asyncio_orm_avoid_lazyloads`
2029
2030 """
2031 trans = self._transaction
2032 if trans is None:
2033 trans = self._autobegin_t()
2034
2035 trans.commit(_to_root=True)
2036
2037 def prepare(self) -> None:
2038 """Prepare the current transaction in progress for two phase commit.

Callers 15

test_queryMethod · 0.95
test_mutableMethod · 0.95
test_modifiedMethod · 0.95
test_queryMethod · 0.95
test_mutableMethod · 0.95
test_modifiedMethod · 0.95
test_cast_typeMethod · 0.95
test_multi_dimensionMethod · 0.95
_test_premature_flushMethod · 0.95
insert_dataMethod · 0.95
insert_dataMethod · 0.95
insert_dataMethod · 0.95

Calls 1

_autobegin_tMethod · 0.95

Tested by 15

test_queryMethod · 0.76
test_mutableMethod · 0.76
test_modifiedMethod · 0.76
test_queryMethod · 0.76
test_mutableMethod · 0.76
test_modifiedMethod · 0.76
test_cast_typeMethod · 0.76
test_multi_dimensionMethod · 0.76
_test_premature_flushMethod · 0.76
insert_dataMethod · 0.76
insert_dataMethod · 0.76
insert_dataMethod · 0.76