#30857: When subclassing a model field, `max_length` cannot be passed as an
argument to `self.__init__`
-------------------------------------+-------------------------------------
               Reporter:  Robin      |          Owner:  nobody
  (Robert) Thomas                    |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:             |        Version:  2.2
  Uncategorized                      |
               Severity:  Normal     |       Keywords:  models fields
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 {{{
 class MyCustomField(models.CharField):
     def __init__(self, *args, **kwargs):
         super().__init__(max_length=60, *args, **kwargs)

 class MyModel(models.Model)
     address_state = MyCustomField()
 }}}

 On attempting to migrate, I get:

 {{{
 super().__init__(max_length=60, *args, **kwargs)
 TypeError: __init__() got multiple values for keyword argument
 'max_length'
 }}}

 Using `kwargs[max_length]` works just fine. However, the documentation
 says that `max_length` should be able to be passed to `super().__init__()`
 as an argument:

 https://docs.djangoproject.com/en/2.2/howto/custom-model-fields/#writing-a
 -field-subclass

 Either the documentation is incorrect and should be fixed, or this is a
 bug.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30857>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/057.3bb4a728117f664c04558d1b8c61a18a%40djangoproject.com.

Reply via email to