Upgrade to 1.11: TypeError build_attrs () accepts at most 2 arguments (3 data)

I am upgrading from 1.10.7 to 1.11.0 and I get the following error when viewing the form. I cannot figure out what is wrong with my form. Other forms work in a similar way. I suspect this might be select2 or markdownx interoperability , but there is no indication that they are incompatible with 1.11.

How can I debug this further?

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/home/usr/repos/intranet/isotek_intranet_site/order_book/views.py" in create
  161.     return render(request, 'order_book/create.html', context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/shortcuts.py" in render
  30.     content = loader.render_to_string(template_name, context, request, using=using)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  68.     return template.render(context, request)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/backends/django.py" in render
  66.             return self.template.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  207.                     return self._render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  177.             return compiled_parent._render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  72.                 result = block.nodelist.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  1046.         return render_value_in_context(output, context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_value_in_context
  1024.     value = force_text(value)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/utils/encoding.py" in force_text
  78.                 s = six.text_type(s)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/utils/html.py" in <lambda>
  376.         klass.__unicode__ = lambda self: mark_safe(klass_unicode(self))

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/boundfield.py" in __str__
  41.         return self.as_widget()

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/boundfield.py" in as_widget
  120.             **kwargs

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in render
  220.         context = self.get_context(name, value, attrs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in get_context
  665.         context = super(Select, self).get_context(name, value, attrs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in get_context
  626.         context = super(ChoiceWidget, self).get_context(name, value, attrs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in get_context
  211.             'attrs': self.build_attrs(self.attrs, attrs),

Exception Type: TypeError at /order_book/create/
Exception Value: build_attrs() takes at most 2 arguments (3 given)

      

Template:

<form action="/order_book/invoice/create/" method="post">
{% csrf_token %}
<input type='hidden' name='action' value='create'>

<table>
    <tr>
        <td>{{ form.active.label }}</td>
        <td>{{ form.active }}</td>
    </tr>
    <!-- other entries like the one above… -->
    <tr>
        <td>
            <button type="submit" value="Add"><img src="/static/images/tick.png" alt="Set">
                Create new project code</button>
        </td>
    </tr>
</table>

      

View:

def create_code(request):  # pragma: no cover
    context = {}
    if request.method == 'POST':
        form = MyForm(request.POST)
        if form.is_valid():
            pass  # Clearly for testing…
    form = MyForm()
    context['form'] = form
    return render(request, 'order_book/create_code.html', context)

      

The form:

class MyForm(forms.ModelForm):

    class Meta:
        model = MyModel
        fields = '__all__'
        widgets = {
           'manager': Select2Widget(attrs={'style': 'min-width:400px'}),
        }

      

+3


source to share


2 answers


They changed the build_attrs function in Django 1.11 /

You may need to update select2 and markdownx with pip as well.



pip install select2 markdownx --upgrade

+1


source


In Django update 1.11 they change the build_attrs class to only use 2 arguments, where now all your additional arguments have to be passed to the dict.

So when you use a custom widget that uses the build_attrs function, you need to change the call to build_attrs:

build_attrs(attrs, foo='bizz', bar='baz')

      



in

build_attrs(attrs, {'foo':'bizz', 'bar':'baz'})

      

So the Select2 class is the culprit. You can fix this by super-categorizing and rewriting the render function with a new method, or you can check if the author has an update.

0


source







All Articles