Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator error when oppening edit form with WTForms 3.2.x #49

Open
jgriffon opened this issue Dec 10, 2024 · 0 comments
Open

Validator error when oppening edit form with WTForms 3.2.x #49

jgriffon opened this issue Dec 10, 2024 · 0 comments

Comments

@jgriffon
Copy link

jgriffon commented Dec 10, 2024

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

INFO:werkzeug:127.0.0.1 - - [10/Dec/2024 08:21:06] "GET /admin/user/edit/?id=1&url=/admin/user/ 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 2149, in edit_view
    form = self.edit_form(obj=model)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\model\base.py", line 1340, in edit_form
    return self._edit_form_class(get_form_data(), obj=obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\form.py", line 209, in __call__
    return type.__call__(cls, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\flask_admin\form\__init__.py", line 22, in __init__
    super(BaseForm, self).__init__(formdata=formdata, obj=obj, prefix=prefix, **kwargs)
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\form.py", line 281, in __init__
    super().__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\form.py", line 49, in __init__
    field = meta.bind_field(self, unbound_field, options)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\meta.py", line 28, in bind_field
    return unbound_field.bind(form=form, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\fields\core.py", line 387, in bind
    return self.field_class(*self.args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\xxx\AppData\Local\pypoetry\Cache\virtualenvs\bMSMjqU3-py3.11\Lib\site-packages\wtforms\fields\core.py", line 133, in __init__
    for k, v in flags.items():
                ^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'items'

This line is no longer allowed :

field_flags = ('unique', )

I take information here :
https://wtforms.readthedocs.io/en/3.2.x/changes/#version-3-2-0
pallets-eco/wtforms#467

New code line might be :

field_flags = {"unique": True}

@jgriffon jgriffon changed the title Error when oppening edit form Error when oppening edit form with WTForms 3.2.x Dec 10, 2024
@jgriffon jgriffon changed the title Error when oppening edit form with WTForms 3.2.x Validator error when oppening edit form with WTForms 3.2.x Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant