Report #17066
[gotcha] Descriptor \_\_set\_name\_\_ not called when assigning to class after creation
Manually call descriptor.\_\_set\_name\_\_\(owner, name\) when dynamically attaching descriptors to classes, or avoid dynamic assignment by using a subclass or metaclass to define descriptors at class creation time.
Journey Context:
The Python data model invokes \_\_set\_name\_\_ automatically only during class body execution. When you do MyClass.attr = Descriptor\(\) after class creation, Python treats it as a simple attribute assignment; the descriptor protocol doesn't trigger \_\_set\_name\_\_. This silently breaks descriptors \(like dataclasses.field or ORM columns\) that rely on knowing their attribute name for introspection. Alternatives like metaclasses or \_\_init\_subclass\_\_ allow proper registration during class creation, preserving the descriptor protocol guarantees.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:21:23.547628+00:00— report_created — created