viur-framework / viur-core

The core component of ViUR, the Python framework for modern web development.
https://www.viur.dev
MIT License
13 stars 14 forks source link

fix: Add `__set_name__` in `__setattr__` for bones #1312

Closed ArneGudermann closed 2 weeks ago

ArneGudermann commented 3 weeks ago

This PR fixes the bug when you clone a skeleton and then add a bone neither the name nor the skelcls are set for this bone.

skel=self.viewSkel().clone()
select = SelectBone(values={"a":1})
skel.__setattr__("x",select)
return self.render.view(skel)

Produce

File "/viur/src/viur/core/bones/select.py", line 102, in __getattribute__
    f"value {key} for {self.name}<{type(self).__name__}> in {self.skel_cls.__name__} in {self.skel_cls}"
AttributeError: 'NoneType' object has no attribute '__name__'.

Many thanks to @skoegl for the find and the report.

skoegl commented 3 weeks ago

This is perhaps my monk mode, but afaik it's more efficient to use self.class.name instead of type(self).name but that can be discussed in another PR draft - have to check against current bytecode / benchmark