Skip to content

Choice error when oppening edit form with WTForms 3.2.x #50

@jgriffon

Description

@jgriffon

I've got this message when I click to edit a row :

INFO:werkzeug:127.0.0.1 - - [10/Dec/2024 08:33:46] "GET /admin/art_article/edit/?id=3289&url=/admin/art_article/ HTTP/1.1" 500 -
ERROR:werkzeug:Error on request:
Traceback (most recent call last):
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\werkzeug\serving.py", line 370, in run_wsgi        
    execute(self.server.app)
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\werkzeug\serving.py", line 331, in execute
    application_iter = app(environ, start_response)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\app.py", line 1536, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\app.py", line 1514, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_restx\api.py", line 672, in error_router     
    return original_handler(e)
           ^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_cors\extension.py", line 194, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
                                                ^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\app.py", line 919, in full_dispatch_request  
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_restx\api.py", line 672, in error_router     
    return original_handler(e)
           ^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_cors\extension.py", line 194, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
                                                ^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\app.py", line 917, in full_dispatch_request  
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\app.py", line 902, in dispatch_request       
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\base.py", line 69, in inner
    return self._run_view(f, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\base.py", line 369, in _run_view       
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\model\base.py", line 2175, in edit_view
    return self.render(template,
           ^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\base.py", line 308, in render
    return render_template(template, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\templating.py", line 150, in render_template 
    return _render(app, template, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask\templating.py", line 131, in _render
    rv = template.render(context)
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\jinja2\environment.py", line 1304, in render       
    self.environment.handle_exception()
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\jinja2\environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "C:\Git\Illico\backend\main_app\templates\admin\edit.html", line 1, in top-level template code
    {% extends 'admin/model/edit.html' %}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\model\edit.html", line 3, in top-level template code
    {% from 'admin/lib.html' import extra with context %} {# backward compatible #}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\master.html", line 1, in top-level template code
    {% extends admin_base_template %}
  File "C:\Git\Illico\backend\main_app\templates\admin\large-layout.html", line 2, in top-level template code
    {% extends 'admin/base.html' %}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\base.html", line 38, in top-level template code
    {% block page_body %}
  File "C:\Git\Illico\backend\main_app\templates\admin\large-layout.html", line 44, in block 'page_body'
    {% block body %}{% endblock %}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\model\edit.html", line 32, in block 'body'
    {% block edit_form %}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\model\edit.html", line 33, in block 'edit_form'
    {{ lib.render_form(form, return_url, extra(), form_opts) }}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\jinja2\runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\lib.html", line 202, in template
    {% call form_tag(action=action) %}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\jinja2\runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\lib.html", line 182, in template
    {{ caller() }}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\jinja2\runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\lib.html", line 203, in template
    {{ render_form_fields(form, form_opts=form_opts) }}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\jinja2\runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\lib.html", line 175, in template
    {{ render_field(form, f, kwargs) }}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\jinja2\runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\templates\bootstrap3\admin\lib.html", line 130, in template
    {{ field(**kwargs)|safe }}
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\fields\core.py", line 164, in __call__     
    return self.meta.render_field(self, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\meta.py", line 64, in render_field
    return field.widget(field, **render_kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\form\widgets.py", line 28, in __call__ 
    return super(Select2Widget, self).__call__(field, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\widgets\core.py", line 374, in __call__    
    val, label, selected, render_kw = choice
ValueError: not enough values to unpack (expected 4, got 3)

This lines are no longer allowed :
[
flask-admin/flask_admin/contrib/sqla/validators.py
](

yield (u'__None', self.blank_text, self.data is None)
)

Every iter_choices functions need to return 4 value :
I take information here :
https://wtforms.readthedocs.io/en/3.2.x/changes/#version-3-2-0
pallets-eco/wtforms#816

new return should include render_kw so it could be :

yield (u'__None', self.blank_text, self.data is None, {})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions