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

3.2.1 - AttributeError: 'tuple' object has no attribute 'items' #864

Closed
macmule opened this issue Oct 22, 2024 · 3 comments
Closed

3.2.1 - AttributeError: 'tuple' object has no attribute 'items' #864

macmule opened this issue Oct 22, 2024 · 3 comments

Comments

@macmule
Copy link

macmule commented Oct 22, 2024

This was originally logged as: pallets-eco/flask-admin#2546

I hit an issue with a couple of my Flask-Admin applications, and can recreate in the attached example.

The issue is that when clicking "Create" or "Edit" Flask-Admin errors with the below traceback:

[2024-10-22 10:11:46 +0100] [73] [ERROR] Error handling request /admin/definitions/new/?url=/admin/definitions/
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/gunicorn/workers/gthread.py", line 282, in handle
    keepalive = self.handle_request(req, conn)
  File "/usr/local/lib/python3.10/dist-packages/gunicorn/workers/gthread.py", line 334, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2552, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2532, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/usr/local/lib/python3.10/dist-packages/flask_admin/base.py", line 69, in inner
    return self._run_view(f, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/flask_admin/base.py", line 369, in _run_view
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/flask_admin/model/base.py", line 2093, in create_view
    form = self.create_form()
  File "/usr/local/lib/python3.10/dist-packages/flask_admin/model/base.py", line 1332, in create_form
    return self._create_form_class(get_form_data(), obj=obj)
  File "/usr/local/lib/python3.10/dist-packages/wtforms/form.py", line 209, in __call__
    return type.__call__(cls, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/flask_admin/form/__init__.py", line 22, in __init__
    super(BaseForm, self).__init__(formdata=formdata, obj=obj, prefix=prefix, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/wtforms/form.py", line 281, in __init__
    super().__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)
  File "/usr/local/lib/python3.10/dist-packages/wtforms/form.py", line 49, in __init__
    field = meta.bind_field(self, unbound_field, options)
  File "/usr/local/lib/python3.10/dist-packages/wtforms/meta.py", line 28, in bind_field
    return unbound_field.bind(form=form, **options)
  File "/usr/local/lib/python3.10/dist-packages/wtforms/fields/core.py", line 387, in bind
    return self.field_class(*self.args, **kw)
  File "/usr/local/lib/python3.10/dist-packages/wtforms/fields/core.py", line 133, in __init__
    for k, v in flags.items():
AttributeError: 'tuple' object has no attribute 'items'

To recreate:

  1. Download the follwoing .zip: Flask-Admin-Test.zip
  2. Double click run.command (check contents of that script 1st.. it's just setting things up to test).
  3. Once completed, navigate in a browser to: http://127.0.0.1:8000/
  4. Click the "Create" option text.
  5. BOOM.. Internal Server Error.. and terminal output will show the same as I've posted in this thread.

The resolution:

Pinning WTForms to 3.1.2 resolved the issue, (3.2.0 errored with ImportError: cannot import name 'SelectFieldBase' from 'wtforms.fields').

@davidism
Copy link
Member

davidism commented Oct 22, 2024

Flask-Admin will need to update to be compatible with the new WTForms feature release. You should reopen that original issue.

@azmeuk
Copy link
Member

azmeuk commented Oct 22, 2024

For the record @macmule, flask-admin uses tuple flags, but they have been deprecated 4 years ago in favor of dict flags (with #467) and the deprecated code have been removed with 3.2 (with #859).

@macmule
Copy link
Author

macmule commented Oct 22, 2024

@azmeuk thanks for the extra information.. so that would be why then :)

I have reopened the issue in the flask-admin repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants