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

Old description:

> {{{
> 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.

New description:

 {{{
 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, or this is a bug.

--

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

Reply via email to