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

Selecting "Create" or "Edit" results in "Internal Error{" due to "AttributeError: 'tuple' object has no attribute 'items'" #2546

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

Comments

@macmule
Copy link

macmule commented Oct 22, 2024

I've 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'

Now, I do apologise if this is the wrong place to start to ask about this issue. But, from the above, you can see it's erroring from the builtin items. So, looking for guidance as to how to proceed.

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.

Environment:

  • Python version: 3.10 (and recreated the same issue on Python 3.9 and 3.12 too)
  • Flask version: 2.3.3
  • Flask-Admin version: 1.6.1

We have flask-admin 1.6.0 running in prod, without issue. But attempts to run the same known-good versions locally hit the same issue.. and locally this is across different macOS hosts.. and also attempted locally in docker and kubernetes with differing Ubuntu releases too.

@macmule
Copy link
Author

macmule commented Oct 22, 2024

..and the issue appears to be related to WTForms.. in prod we're running 3.1.2.. and latest is 3.2.1 and generates this issue.

As such, I'll close this off here.. and raise at: https://github.com/pallets-eco/wtforms

@macmule
Copy link
Author

macmule commented Oct 22, 2024

Reopening as per the following comment on the WTForms issue (pallets-eco/wtforms#864 (comment))

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

@townxelliot
Copy link

I have encountered the same issue today; it happens with WTForms 3.2.0 and 3.2.1. My temporary solution is to pin WTForms to 3.1.2.

@samuelhwilliams
Copy link
Contributor

The underlying issue here was fixed recently in this PR: #2341

It's currently available as Flask-Admin v2.0.0a. Please note this is a pre-release version of v2, so it is not guaranteed to be stable. I've been using it successfully and without issue for a while now though.

I would suggest trying it out, but be careful before using it in production.

Also consider following #2451 to track when v2.0.0 officially releases.

I will close this for now as I believe the issue in code is fixed - it is a matter of getting a v2.0.0 release published.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants