#12568: SubFieldBase descriptor object should be accessible
--------------------------------------+-------------------------------------
Reporter: specialunderwear | Owner: nobody
Status: new | Milestone: 1.2
Component: Uncategorized | Version: 1.2-alpha
Keywords: SubFieldBase subclassing | Stage: Unreviewed
Has_patch: 1 |
--------------------------------------+-------------------------------------
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.
--
Ticket URL: <
http://code.djangoproject.com/ticket/12568>
Django <
http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.