#28490: Descriptors on Models are reported as nonexistent by System Check 
for ModelAdmin.list_display if they return None
     Reporter:  Hunter Richards      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.admin        |                  Version:  master
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  admin, descriptor,   |             Triage Stage:  Accepted
  system, checks, framework,         |
  validation                         |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0

Comment (by ajcsimons):

 Unfortuantely this fix causes other bugs:
 1. if hasattr(obj.model, item) returns false then we go straight to the
 else clause which returns the error,
 2. whereas before the else clause did another check for
 model._meta.get_field(item) and would only return the error if that raised
 a FieldDoesNotExist exception
 3. So how is it that hasattr(model, item) can return false, but
 model._meta.get_field(item) will return something meaning the check should
 not return an error?
 4. Answer: the field is a special one which is only valid to access on
 instances of the model (whose ModelAdmin we are verifying) and not the
 model class itself. An example of this is the PositionField from the
 django-positions library (which inherits from djangos
     def __get__(self, instance, owner):
         if instance is None:
             raise AttributeError("%s must be accessed via instance." %
         current, updated = getattr(instance, self.get_cache_name())
         return current if updated is None else updated

Ticket URL: <https://code.djangoproject.com/ticket/28490#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to