#20813: max_length incorrectly passed to MultiValueField-derived class
----------------------------------------------+--------------------
     Reporter:  george_edison                 |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.5
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 I have created a custom model field that looks something like this:

 {{{
 class TestModelField(models.CharField):
     __metaclass__ = models.SubfieldBase

     def __init__(self, *args, **kwargs):
         kwargs['max_length'] = 10
         super(TestModelField, self).__init__(*args, **kwargs)

     # ... to_python and get_prep_value omitted ...

     def formfield(self, **kwargs):
         defaults = {'form_class': TestFormField,}
         defaults.update(kwargs)
         return super(TestModelField, self).formfield(**defaults)
 }}}

 The `TestFormField` class looks something like this:

 {{{
 class TestFormField(forms.MultiValueField):
     widget = TestWidget

     def __init__(self, *args, **kwargs):
         fields = (
             forms.IntegerField(min_value=0, max_value=15),
             forms.IntegerField(min_value=0, max_value=15),
         )
         super(TestFormField, self).__init__(fields, *args, **kwargs)

     # ... compress omitted ...
 }}}

 The problem lies in the fact that `TestFormField.__init__` is receiving
 `max_length` in `kwargs`. Because this eventually gets passed along to
 `Field.__init__` which doesn't have a `max_length` named parameter, an
 error is raised:

 {{{
 TypeError: __init__() got an unexpected keyword argument 'max_length'
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20813>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.0763710a479b2dd3670d953f11ac55cd%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to