--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -350,6 +350,8 @@
     CLEAR_DBT(*key);
     if (keyobj == Py_None) {  /* TODO: is None really okay for keys? */
         type = _DB_get_type(self);
+        if (type == -1)
+            return 0;
         if (type == DB_RECNO || type == DB_QUEUE) {
             PyErr_SetString(
                 PyExc_TypeError,