-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
sqlite3 package document mistake #86790
Comments
In the document about sqlite3 package, it was suggested that when users are trying to create a table already exists, sqlite3.ProgrammingError is going to be thrown. However, the actual exception thrown is sqlite3.OperationalError, which is inconsistent with the document. Doc: https://docs.python.org/3/library/sqlite3.html#exceptions |
The doc is the same in 3.10. What OS and exact Python release? Can you post minimal code that verifies your claim? (Someone what have to verify with 3.10 also.) This would strike me as an error in the code. We can fix 'wrong Exception' in the next release. I am not sure whether we would do so in a current release. |
Python 3.9.1 (default, Dec 11 2020, 14:32:07)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> conn = sqlite3.connect("test.db")
>>> conn.execute("CREATE TABLE test (id INTEGER, str TEXT);")
<sqlite3.Cursor object at 0x7ff99f2df3b0>
>>> conn.execute("CREATE TABLE test (id INTEGER, str TEXT);")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.OperationalError: table test already exists
>>> I think the reproduction is way too easy and has nothing special so I didn't include one at the very beginning. That's a simple reproduction on interactive console. |
Exception originates from _pysqlite_seterror() in Modules/_sqlite/util.c, line 64: Error code 1 (SQLITE_ERROR, https://sqlite.org/rescode.html#error) is a generic sqlite3 error. Changing the default sqlite3 exception for this error code may not be what we want. Anyway, we should clean up the exceptions emitted in the sqlite3 module. There are other inconsistencies apart from this. |
*error handling => exception emitted |
The sqlite3 exception docs section has been rewritten in |
We could backport gh-27645 to 3.11, and possibly also 3.10, but it will be hairy. |
I backported gh-27645 to 3.11 and 3.10:
I consider this issue resolved. If there are further inconsistencies, please open a new issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: