From 14913a447cb0683dfdac33bdd16b50f840d9027b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 21 Mar 2025 11:29:59 +0100 Subject: [PATCH] Fix #136294: Blender 4.4 is discarding exceptions occurred in operator's constructor While using constructors in Operator classes is _really_ not recommended, BPY code was a bit too eager to overwrite existing errors with its own generic messages. Now only generate these exceptions if there is no other exception already set. --- source/blender/python/intern/bpy_rna.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/blender/python/intern/bpy_rna.cc b/source/blender/python/intern/bpy_rna.cc index 2b92daf5dc1..2653622e7da 100644 --- a/source/blender/python/intern/bpy_rna.cc +++ b/source/blender/python/intern/bpy_rna.cc @@ -8304,7 +8304,9 @@ static PyObject *pyrna_struct_CreatePyObject_from_type(const PointerRNA *ptr, #endif if (pyrna == nullptr) { - PyErr_SetString(PyExc_MemoryError, "couldn't create bpy_struct object"); + if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_MemoryError, "couldn't create bpy_struct object"); + } return nullptr; } @@ -9450,10 +9452,16 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param } else if (py_srna == nullptr) { py_class_instance = nullptr; + if (PyErr_Occurred()) { + err = -1; /* So the error is not overridden below. */ + } } else if (py_srna == Py_None) { /* Probably won't ever happen, but possible. */ Py_DECREF(py_srna); py_class_instance = nullptr; + if (PyErr_Occurred()) { + err = -1; /* So the error is not overridden below. */ + } } else { #if 0 @@ -9510,7 +9518,9 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param #endif if (py_class_instance == nullptr) { - err = -1; /* So the error is not overridden below. */ + if (PyErr_Occurred()) { + err = -1; /* So the error is not overridden below. */ + } } Py_DECREF(py_srna);