gpt4 book ai didi

python - SQLalchemy : ValueError too many values to unpack?

转载 作者:行者123 更新时间:2023-12-01 21:40:03 25 4
gpt4 key购买 nike

我有一个使用 sql-alchemy 包运行 mysql 数据库的网站,但突然损坏了。我做了一些研究,发现预期的问题是最新的 sql-alchemy 更新为 Flask-admin 提供了比预期更多的值

"cls, key = identity_key(instance=obj)"


Source

建议的修复方法是编辑文件以接受第三项,但我无法使用我在环境中拥有的权限来执行此操作。

另一个答案链接到 github 上的存储库,但我不知道这对我有什么帮助。我对此很陌生,我不知道我是否应该克隆该存储库,或者如果我应该克隆该存储库,该怎么做。

感谢任何帮助!

这是错误转储

2018-01-22 20:01:59,593: [2018-01-22 20:01:59,592] ERROR in app: Exception on /reservation/add [GET]
2018-01-22 20:01:59,594: Traceback (most recent call last):
2018-01-22 20:01:59,594:
File "fakepath/flask/app.py", line 1982, in wsgi_app
2018-01-22 20:01:59,594: response = self.full_dispatch_request()2018-01-22 20:01:59,594: File "fakepath/flask/app.py", line 1614, in full_dispatch_request
2018-01-22 20:01:59,594: rv = self.handle_user_exception(e)
2018-01-22 20:01:59,595: File "fakepath/flask/app.py", line 1517, in handle_user_exception2018-01-22 20:01:59,595: reraise(exc_type, exc_value, tb)2018-01-22 20:01:59,595: File "fakepath/flask/_compat.py", line 33, in reraise
2018-01-22 20:01:59,595: raise value2018-01-22 20:01:59,595: File "fakepath/flask/app.py", line 1612, in full_dispatch_request
2018-01-22 20:01:59,595: rv = self.dispatch_request()
2018-01-22 20:01:59,596: File "fakepath/flask/app.py", line 1598, in dispatch_request2018-01-22 20:01:59,596: return self.view_functionsrule.endpoint
2018-01-22 20:01:59,596: File "fakepath/flask_login/utils.py", line 261, in decorated_view
2018-01-22 20:01:59,596: return func(*args, **kwargs)
2018-01-22 20:01:59,597: File "/home/apoalphagammawebmaster/inventory/app/auth/views.py", line 248, in add_reservation
2018-01-22 20:01:59,597: form=form, title='Add Reservation')
2018-01-22 20:01:59,597: File "fakepath/flask/templating.py", line 134, in render_template2018-01-22 20:01:59,597: context, ctx.app)
2018-01-22 20:01:59,597: File "fakepath/flask/templating.py", line 116, in _render
2018-01-22 20:01:59,597: rv = template.render(context)
2018-01-22 20:01:59,598: File "fakepath/jinja2/asyncsupport.py", line 76, in render
2018-01-22 20:01:59,598: return original_render(self, *args, **kwargs)2018-01-22 20:01:59,598: File "fakepath/jinja2/environment.py", line 1008, in render
2018-01-22 20:01:59,598: return self.environment.handle_exception(exc_info, True)
2018-01-22 20:01:59,598: File "fakepath/jinja2/environment.py", line 780, in handle_exception
2018-01-22 20:01:59,599: reraise(exc_type, exc_value, tb)
2018-01-22 20:01:59,599: File "fakepath/jinja2/_compat.py", line 37, in reraise
2018-01-22 20:01:59,599: raise value.with_traceback(tb)
2018-01-22 20:01:59,599: File "/home/apoalphagammawebmaster/inventory/app/templates/auth/reservations/reservation.html", line 2, in top-level template code
2018-01-22 20:01:59,599:
{% extends "base.html" %}
2018-01-22 20:01:59,599: File "/home/apoalphagammawebmaster/inventory/app/templates/base.html", line 48, in top-level template code
2018-01-22 20:01:59,600: {% block body %}
2018-01-22 20:01:59,600: File "/home/apoalphagammawebmaster/inventory/app/templates/auth/reservations/reservation.html", line 27, in block "body"
2018-01-22 20:01:59,600: {{ wtf.quick_form(form) }}
2018-01-22 20:01:59,600: File "fakepath/jinja2/runtime.py", line 579, in _invoke
2018-01-22 20:01:59,600: rv = self._func(*arguments)
2018-01-22 20:01:59,601: File "fakepath/flask_bootstrap/templates/bootstrap/wtf.html", line 205, in template
2018-01-22 20:01:59,601: {{ form_field(field,2018-01-22 20:01:59,601: File "fakepath/jinja2/runtime.py", line 579, in _invoke
2018-01-22 20:01:59,601: rv = self._func(*arguments)
2018-01-22 20:01:59,601: File "fakepath/flask_bootstrap/templates/bootstrap/wtf.html", line 123, in template
2018-01-22 20:01:59,601:
{{field(class="form-control", **kwargs)|safe}}
2018-01-22 20:01:59,601: File "fakepath/wtforms/fields/core.py", line 153, in call
2018-01-22 20:01:59,601: return self.meta.render_field(self, kwargs)
2018-01-22 20:01:59,602:
File "fakepath/wtforms/meta.py", line 56, in render_field2018-01-22 20:01:59,602: return field.widget(field, **render_kw)
2018-01-22 20:01:59,602: File "fakepath/wtforms/widgets/core.py", line 287, in call2018-01-22 20:01:59,602: for val, label, selected in field.iter_choices():
2018-01-22 20:01:59,602: File "fakepath/wtforms/ext/sqlalchemy/fields.py", line 107, in iter_choices
2018-01-22 20:01:59,602: for pk, obj in self._get_object_list():
2018-01-22 20:01:59,602: File "fakepath/wtforms/ext/sqlalchemy/fields.py", line 100, in _get_object_list
2018-01-22 20:01:59,602: self._object_list = list((text_type(get_pk(obj)), obj) for obj in query)
2018-01-22 20:01:59,603: File "fakepath/wtforms/ext/sqlalchemy/fields.py", line 100, in
2018-01-22 20:01:59,603: self._object_list = list((text_type(get_pk(obj)), obj) for obj in query)
2018-01-22 20:01:59,603: File "fakepath/wtforms/ext/sqlalchemy/fields.py", line 189, in get_pk_from_identity
2018-01-22 20:01:59,603: cls, key = identity_key(instance=obj)
2018-01-22 20:01:59,603: ValueError: too many values to unpack (expected 2)

最佳答案

该问题已在 github 问题线程中涵盖 - https://github.com/flask-admin/flask-admin/issues/1588

基本上,flask-admin pip 包已过时,就最新的 sqlalchemy 而言点包。在该特定区域中,

cls, key = identity_key(instance=obj)

sqlalchemy现在返回 3 个对象,但是 flask-admin仅期望 2,因此出现错误。

真正的解决方案是等到新的 flask-admin版本已上传到 pip,在此之前,您有几个选择。

  1. 手动进入并编辑 fields.py文件
  2. 正如该问题线程中详细说明的,限制 sqlalchemy至版本1.2.0b3 。您可以在requirements.txt 文件中执行此操作,或使用pip 升级安装手动执行此操作,pip install --upgrade sqlalchemy==1.2.0b3
  3. 修复位于 flask-admin在其 github 存储库中的 master 分支,安装该版本的 flask-admin点位置为git+https://github.com/flask-admin/flask-admin 。同样,您可以在requirements.txt文件中执行此操作,或者使用pip升级安装pip install --upgrade git+https://github.com/flask-admin/flask-admin .

我个人的偏好,以及我所做的,是选项 3。如果你仔细查看代码本身,无论如何,这是维护者想要删除的一行,而且他们处理它的方式更好,并且在一般来说,对于这些事情,我更喜欢前进(最新版本的 flask-admin )而不是拖延事情(回滚 sqlalchemy 到以前的版本),当然比手动编辑原始代码更好。

关于python - SQLalchemy : ValueError too many values to unpack?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48390207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com