#28198: Doesn't override existing class attributes with a deferred instance
attribute
-------------------------------+--------------------------------------
     Reporter:  Ryan Hiebert   |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Uncategorized  |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by Aymeric Augustin):

 Regarding the piece of code highlighted in the report above, I don't
 understand why fields shouldn't override classmethods.

 If I look at this piece of code:

 class A(models.Model):

     @classmethod
     def foo(self, bar):
         raise FooError


 class B(A):

     foo = models.FooField()

 and guess what B().foo(bar) does, I'm not guessing "FooError", I'm saying
 "TypeError: ... is not callable".

 Simply removing the condition breaks the tests for multiple inheritance,
 for reasons I haven't quite figured out.

 In `django.db.models.base.ModelBase` (the metaclass for `Model`) Django
 builds inherited models child-to-parent by tracking which fields are
 already defined, likely to avoid calling `contribute_to_class` on fields
 from parents that are overridden in fields from children. This code is a
 bit complicated and I'm having trouble figuring out how to modify it.

--
Ticket URL: <https://code.djangoproject.com/ticket/28198#comment:1>
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/069.c20e1206fd417afb8e322e5fd3f2f74a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to