#18480: Inherited model fails to handle blank field properly
-------------------------------------+-------------------------------------
     Reporter:  yuval_a              |                    Owner:  navi7
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.4
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by navi7):

 This is a kind of red herring.

 The actual problem stems from the model coming up with the same field name
 as name of the derived class itself so it can have the reference to the
 base class. Model building then just overwrites our field. The simplest
 test is this:

 {{{
 #!python
 class FruitFly(models.Model):
     pass

 class CroatianFruitFly(FruitFly):
     croatianfruitfly = models.IntegerField()


 fly2 = CroatianFruitFly()  #  this throws wrong exception
 }}}

 The error thrown is:
 {{{
 #!python
 ValueError: Cannot assign None: "CroatianFruitFly.croatianfruitfly" does
 not allow null values.
 }}}
 And that's totally misleading.

 As I'm totally new to Django, I don't know a way out of it. It seems that
 using the same field name as the class can be explicitly forbidden by
 throwing meaningful errors when the model is built. Then again, that could
 potentially be a breaking change.

 Or, the name of the reference could be mangled somehow to not use that
 exact name.

 Anyways, I need someone who knows the internals a bit more to look at
 this.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18480#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 [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/065.ccc9b7d27755fe12dfcbcc7f474db736%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to