--- a/src/python/recoll/pyrecoll.cpp
+++ b/src/python/recoll/pyrecoll.cpp
@@ -612,6 +612,11 @@
     LOGDEB0(("Doc_setattr: doc %p\n", self->doc));
     if (self->doc == 0 || the_docs.find(self->doc) == the_docs.end()) {
         PyErr_SetString(PyExc_AttributeError, "doc??");
+	return -1;
+    }
+    if (!rclconfig || !rclconfig->ok()) {
+	PyErr_SetString(PyExc_EnvironmentError,
+                        "Configuration not initialized");
 	return -1;
     }