bpo-32788: Better error handling in sqlite3. (GH-3723) · python/cpython@fc662ac · GitHub
Skip to content

Commit fc662ac

Browse files
bpo-32788: Better error handling in sqlite3. (GH-3723)
Propagate unexpected errors (like MemoryError and KeyboardInterrupt) to user.
1 parent dffccc6 commit fc662ac

7 files changed

Lines changed: 156 additions & 124 deletions

File tree

Lib/sqlite3/test/types.py

Lines changed: 25 additions & 3 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Errors other than :exc:`TypeError` raised in methods ``__adapt__()`` and
2+
``__conform__()`` in the :mod:`sqlite3` module are now propagated to the
3+
user.

Modules/_sqlite/cache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
119119
pysqlite_Node* ptr;
120120
PyObject* data;
121121

122-
node = (pysqlite_Node*)PyDict_GetItem(self->mapping, key);
122+
node = (pysqlite_Node*)PyDict_GetItemWithError(self->mapping, key);
123123
if (node) {
124124
/* an entry for this key already exists in the cache */
125125

@@ -157,7 +157,11 @@ PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
157157
}
158158
ptr->prev = node;
159159
}
160-
} else {
160+
}
161+
else if (PyErr_Occurred()) {
162+
return NULL;
163+
}
164+
else {
161165
/* There is no entry for this key in the cache, yet. We'll insert a new
162166
* entry in the cache, and make space if necessary by throwing the
163167
* least used item out of the cache. */

Modules/_sqlite/connection.c

Lines changed: 6 additions & 2 deletions

0 commit comments

Comments
 (0)