#16176: Overwriting a property with field during model inheritance.
-------------------------------------+-------------------------------------
     Reporter:  czepiel.artur@…      |                    Owner:
                                     |  Thomas_Moronez
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Phist0ne):

 I stumbled upon this bug lately using django 1.8 and am willing to provide
 a patch.

 The main problem seems that creating an attribute containing a django
 field on a model does not overwrite any descriptors (with `__set__`
 defined) from ancestor classes, which does not match the behavior of
 standard python classes.
 It makes sense to me that the attributes corresponding to model fields are
 not set until the class is instantiated, since the values for these fields
 are not available on class creation.
 Therefore my suggested solution would be very similar to Thomas_Moronez's
 patch. What confuses me though is that the proposed patch seems to not
 call contribute_to_class.

 In my opinion there are three possible solutions:
   * delete all class attributes that will be overwritten by fields later
 (e.g. in add_to_class after the "contribute-to-class" check")
   * delete class attributes that have a `__set__` method defined
   * set the class attributes to a specific value (e.g. a to be written
 class) to mark them as to be overwritten later (melinath's suggestion)

 Is this still considered a bug and if so which one is the preferred
 solution?

--
Ticket URL: <https://code.djangoproject.com/ticket/16176#comment:9>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/081.254859b670457a79a8fce52d26dda428%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to