Fix #146588: raise exception when attempting invalid idproperty renaming in Python

Each name has to be unique within a group, so when renaming an idproperty, one
has to make sure that the parent group does not contain duplicates afterwards.
This patch raises a `NameError` when setting the name to one that exists
already. Alternatively, one could delete the already-existing property, but that
seems unexpected and the user should rather do that explicitly.

This also adds a new unit test for this case.

Pull Request: https://projects.blender.org/blender/blender/pulls/146892
This commit is contained in:
Jacques Lucke
2025-09-29 13:54:08 +02:00
parent eef971e377
commit 4d91f5c8ef
2 changed files with 17 additions and 0 deletions

View File

@@ -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.