diff --git a/source/blender/python/generic/idprop_py_api.cc b/source/blender/python/generic/idprop_py_api.cc index 52678016496..7913f36c8cd 100644 --- a/source/blender/python/generic/idprop_py_api.cc +++ b/source/blender/python/generic/idprop_py_api.cc @@ -272,6 +272,15 @@ static int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void * /*c PyErr_SetString(PyExc_TypeError, "string length cannot exceed 63 characters!"); return -1; } + if (STREQ(name, self->prop->name)) { + return 0; + } + if (IDProperty *parent = self->parent) { + if (IDP_GetPropertyFromGroup(parent, name)) { + PyErr_SetString(PyExc_NameError, "property name already exists in parent group"); + return -1; + } + } memcpy(self->prop->name, name, name_len + 1); return 0; diff --git a/tests/python/bl_pyapi_idprop.py b/tests/python/bl_pyapi_idprop.py index b6d876cc883..b281c733a5e 100644 --- a/tests/python/bl_pyapi_idprop.py +++ b/tests/python/bl_pyapi_idprop.py @@ -203,6 +203,14 @@ class TestIdPropertyCreation(TestHelper, unittest.TestCase): with self.assertRaises(TypeError): self.id[self.key_id] = self + def test_rename(self): + self.id["foo"] = {"a": 1} + self.id["bar"] = {"b": 2} + self.id["foo"].name = "foo" + self.id["bar"].name = "bar" + with self.assertRaises(NameError): + self.id["foo"].name = "bar" + class TestIdPropertyUIData(TestHelper, unittest.TestCase): # Default testing idprop key identifier.