SubFieldBase descriptor object should be accessible
|Reported by:||Lars van de Kerkhof||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
Currently any field that has SubFieldBase as a metaclass will throw an exception if you try access the descriptor object without an instance.
Things like the following can not be done with the current implementation:
def _get_members_of_type(obj, member_type): """ Finds members of a certain type in obj. """ def filter_member_type(member): try: return type(member) is member_type except AttributeError: return False # if the type of obj is the metaclass for all models, just search in the object # because it is not a model instance but a type if type(obj) is ModelBase: key_hash = inspect.getmembers(obj, filter_member_type) else: key_hash = inspect.getmembers(obj.__class__, filter_member_type) return key_hash
SubFieldBase will throw an AttributeError every time inspect.getmembers is used on a model instance or class.
Normal behaviour would be to return the descriptor object when no instance is passed. All django's standard fields
behave this way, so it would be best if SubFieldBase would do the same.
I will attach a patch against current trunk.
Change History (15)
comment:1 Changed 7 years ago by
|Patch needs improvement:||unset|