summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-09-28 11:43:48 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-09-28 11:43:48 -0400
commit1ec7ba52e1c7e6d232223912f154e25252fb9b92 (patch)
tree263341ecd7d35c1b39caff1205be99ddf74ba9aa /lib
parente1a923dc5ab70ed0d0a259614f9ecd6e2b78c216 (diff)
downloadsqlalchemy-1ec7ba52e1c7e6d232223912f154e25252fb9b92.tar.gz
- add more dragons to session.begin() / autocommit docs
Change-Id: I9e326f353d396321565dfbf53b7a30f18d8c86e9
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/session.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 0287f1cfb..cfad2ca43 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -794,20 +794,35 @@ class Session(_SessionClassMethods):
def begin(self, subtransactions=False, nested=False):
"""Begin a transaction on this :class:`.Session`.
- The :meth:`.Session.begin` method is only
- meaningful if this session is in **autocommit mode** prior to
- it being called; see :ref:`session_autocommit` for background
- on this setting.
+ .. warning::
- The method will raise an error if this :class:`.Session`
- is already inside of a transaction, unless
- :paramref:`.Session.begin.subtransactions` or
- :paramref:`.Session.begin.nested` are specified.
+ The :meth:`.Session.begin` method is part of a larger pattern
+ of use with the :class:`.Session` known as **autocommit mode**.
+ This is essentially a **legacy mode of use** and is
+ not necessary for new applications. The :class:`.Session`
+ normally handles the work of "begin" transparently, which in
+ turn relies upon the Python DBAPI to transparently "begin"
+ transactions; there is **no need to explcitly begin transactions**
+ when using modern :class:`.Session` programming patterns.
+ In its default mode of ``autocommit=False``, the
+ :class:`.Session` does all of its work within
+ the context of a transaction, so as soon as you call
+ :meth:`.Session.commit`, the next transaction is implicitly
+ started when the next database operation is invoked. See
+ :ref:`session_autocommit` for further background.
+
+ The method will raise an error if this :class:`.Session` is already
+ inside of a transaction, unless
+ :paramref:`~.Session.begin.subtransactions` or
+ :paramref:`~.Session.begin.nested` are specified. A "subtransaction"
+ is essentially a code embedding pattern that does not affect the
+ transactional state of the database connection unless a rollback is
+ emitted, in which case the whole transaction is rolled back. For
+ documentation on subtransactions, please see
+ :ref:`session_subtransactions`.
:param subtransactions: if True, indicates that this
- :meth:`~.Session.begin` can create a subtransaction if a transaction
- is already in progress. For documentation on subtransactions, please
- see :ref:`session_subtransactions`.
+ :meth:`~.Session.begin` can create a "subtransaction".
:param nested: if True, begins a SAVEPOINT transaction and is equivalent
to calling :meth:`~.Session.begin_nested`. For documentation on