Repository navigation
Improve docs/docstrings of sqlite3 commit()/rollback() and close() #93925
Description
Activity
- addeddocsDocumentation in the Doc dirDocumentation in the Doc dir
on Jun 17, 2022 - linked a pull request that will close this issuegh-93925: Improve doc clarity of sqlite3 commit/rollback, and close #93926
on Jun 17, 2022 PEP-249 says this about commit (the first sentence is of importance here):
Commit any pending transaction to the database.
Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on.
Database modules that do not support transactions should implement this method with void functionality.... and this about rollback (the second sentence is of importance here):
This method is optional since not all databases provide transaction support. [3]
In case a database does provide transactions this method causes the database to roll back to the start of any pending transaction. Closing a connection without committing the changes first will cause an implicit rollback to be performed.Note, the proposed
autocommitattribute will fix the auto-commit issues of sqlite3. That proposed feature will also fix the last sentence of the rollback specification; per now, an implicit rollback is not performed on close. No transaction control is performed on close.PEP-249 says this about close:
Close the connection now (rather than whenever .del() is called).
The connection will be unusable from this point forward; an Error (or subclass) exception will be raised if any operation is attempted with the connection. The same applies to all cursor objects trying to use the connection. Note that closing a connection without committing the changes first will cause an implicit rollback to be performed.We raise ProgrammingError if any operation is attempted with closed connections:
cpython/Modules/_sqlite/connection.c
Lines 504 to 520 in e37a158
int pysqlite_check_connection(pysqlite_Connection* con) { if (!con->initialized) { pysqlite_state *state = pysqlite_get_state_by_type(Py_TYPE(con)); PyErr_SetString(state->ProgrammingError, "Base Connection.__init__ not called."); return 0; } if (!con->db) { PyErr_SetString(con->state->ProgrammingError, "Cannot operate on a closed database."); return 0; } else { return 1; } } No implicit rollback is performed at the moment. This will change in the future with the
autocommitattribute.- added a commit that references this issue
on Jun 19, 2022 - added a commit that references this issue
on Jun 19, 2022 - added a commit that references this issue
on Jun 26, 2022
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Originally posted by @mwichmann in #93890 (comment):
The wording of the docs and docstrings for the commit, rollback, and close connection methods can be improved, in order to provide more clarity around transaction handling.
Fixed with: