8000 gh-61162: Clarify sqlite3 connection context manager docs by erlend-aasland · Pull Request #93890 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-61162: Clarify sqlite3 connection context manager docs #93890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clarify?
  • Loading branch information
erlend-aasland committed Jun 16, 2022
commit 76319b7f143a2cc426d0c3f2fba2e467ed9f4b39
18 changes: 13 additions & 5 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1434,13 +1434,21 @@ case-insensitively by name:
Using the connection as a context manager
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

With an open transaction, connection objects can be used as context managers
that automatically commit or rollback transactions.
If the body of the ``with`` statement finishes without exceptions,
Connection objects can be used as context managers that automatically commit or
rollback open transactions when leaving the body of the context manager.
If the body of the :keyword:`with` statement finishes without exceptions,
the transaction is committed.
If an exception is raised and not caught, the transaction is rolled back.
If this commit fails, the transaction is rolled back.
If the body of the ``with`` statement raise an exception which is not caught,
the transaction is rolled back.

If there is no open transaction, the context manager is a no-op.
If there is no open transaction upon leaving the body of the ``with`` statement,
the context manager is a no-op.

.. note::

The context manager does not implicitly open a new transaction.
The context manager does not close the connection.

.. literalinclude:: ../includes/sqlite3/ctx_manager.py

Expand Down
0