SQL炼金术:ValueError太多值无法解包? [英] SQL-alchemy: ValueError too many values to unpack?

查看:102
本文介绍了SQL炼金术:ValueError太多值无法解包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用sql-alchemy软件包运行mysql数据库的网站,该软件包突然坏了.我已经进行了一些研究,发现预期的问题是最新的sql-alchemy更新正在为flask-admin提供比预期的多一个值.

I have a website running with a mysql database using the sql-alchemy package that has suddenly broken. I have done some research and found that the expected issue is that the newest sql-alchemy update is handing flask-admin one more value than expected from

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


来源

建议的解决方法是编辑文件以接受第三个项目,但是我无法获得对环境的权限.


Source

The suggested fix is to edit the files to accept a third item but I am unable to do this with the permissions I have on my environment.

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

Another answer links to a repo on github but I cannot figure out how that helps me. I'm very new to this and I don't know if I am supposed to clone the repo or how exactly to do that if I am.

感谢您的帮助!

这是错误转储

2018-01-22 20:01:59,593:[2018-01-22 20:01:59,592]应用程序错误: /reservation/add [GET]的异常
2018-01-22 20:01:59,594: 追溯(最近一次通话):
2018-01-22 20:01:59,594:
wsgi_app中的文件``fakepath/flask/app.py'',第1982行,
2018-01-22 20:01:59,594:响应= self.full_dispatch_request()2018-01-22 20:01:59,594:文件"fakepath/flask/app.py",行1614, 在full_dispatch_request
2018-01-22 20:01:59,594:rv = self.handle_user_exception(e)
2018-01-22 20:01:59,595:文件 handle_user_exception2018-01-22 20:01:59,595中的"fakepath/flask/app.py"行1517:reraise(exc_type,exc_value,tb)2018-01-22 20:01:59,595:文件"fakepath/flask/_compat.py",行 33,在筹款中
2018-01-22 20:01:59,595:提高价值2018-01-22 20:01:59,595:文件"fakepath/flask/app.py",第1612行, 在full_dispatch_request
2018-01-22 20:01:59,595:rv = self.dispatch_request()
2018-01-22 20:01:59,596:文件 在dispatch_request2018-01-22 20:01:59,596中,"fakepath/flask/app.py"行1598行:返回 self.view_functionsrule.endpoint
2018-01-22 20:01:59,596:在第261行中输入文件"fakepath/flask_login/utils.py" 装饰_视图
2018-01-22 20:01:59,596:返回func(* args, ** kwargs)
2018-01-22 20:01:59,597:文件"/home/apoalphagammawebmaster/inventory/app/auth/views.py",第248行, 在add_reservation
2018-01-22 20:01:59,597:form = form, title ='添加预订')
2018-01-22 20:01:59,597:文件 "fakepath/flask/templating.py",第134行,位于render_template2018-01-22 20:01:59,597:上下文,ctx.app)
2018-01-22 20:01:59,597:在第116行中输入文件"fakepath/flask/templating.py" _render
2018-01-22 20:01:59,597:rv = template.render(context)
2018-01-22 20:01:59,598:文件 渲染中的``fakepath/jinja2/asyncsupport.py'',第76行
2018-01-22 20:01:59,598:返回original_render(self,* args,** kwargs)2018-01-22 20:01:59,598:文件"fakepath/jinja2/environment.py", 第1008行,在render
2018-01-22 20:01:59,598:返回 self.environment.handle_exception(exc_info,True)
2018-01-22 20:01:59,598:在第780行中输入文件"fakepath/jinja2/environment.py" handle_exception
2018-01-22 20:01:59,599:重新筹集(exc_type, exc_value,tb)
2018-01-22 20:01:59,599:文件 "fakepath/jinja2/_compat.py",第37行,正在重新发布
2018-01-22 20:01:59,599:提高价值.with_traceback(tb)
2018-01-22 20:01:59,599:文件 "/home/apoalphagammawebmaster/inventory/app/templates/auth/reservations/reservation.html", 第2行,顶层模板代码中的
2018-01-22 20:01:59,599:
{%扩展了"base.html"%}
2018-01-22 20:01:59,599:文件 "/home/apoalphagammawebmaster/inventory/app/templates/base.html",第 48,在顶级模板代码中
2018-01-22 20:01:59,600:{% 块体%}
2018-01-22 20:01:59,600:文件 "/home/apoalphagammawebmaster/inventory/app/templates/auth/reservations/reservation.html", 第27行,在正文"块中
2018-01-22 20:01:59,600:{{ wtf.quick_form(form)}}
2018-01-22 20:01:59,600:文件 _invoke中的"fakepath/jinja2/runtime.py",第579行,
2018-01-22 20:01:59,600:rv = self._func(* arguments)
2018-01-22 20:01:59,601:文件 "fakepath/flask_bootstrap/templates/bootstrap/wtf.html",第205行,在 模板
2018-01-22 20:01:59,601:{{form_field(field,2018-01-22 20:01:59,601:文件"fakepath/jinja2/runtime.py",行 579,in _invoke
2018-01-22 20:01:59,601:rv = self._func(* arguments)
2018-01-22 20:01:59,601:文件 "fakepath/flask_bootstrap/templates/bootstrap/wtf.html",第123行,在 模板
2018-01-22 20:01:59,601:
{{field(class ="form-control",** kwargs)| safe}}
2018-01-22 20:01:59,601:文件"fakepath/wtforms/fields/core.py",第153行,在 电话
2018-01-22 20:01:59,601:返回self.meta.render_field(self,kwargs)
2018-01-22 20:01:59,602:
在render_field2018-01-22 20:01:59,602中,文件"fakepath/wtforms/meta.py",第56行,返回:field.widget(field, ** render_kw)
2018-01-22 20:01:59,602:文件调用 2018-01-22 20中:01:59,602:对于val,label,在 field.iter_choices():
2018-01-22 20:01:59,602:文件 第107行中的"fakepath/wtforms/ext/sqlalchemy/fields.py" iter_choices
2018-01-22 20:01:59,602:对于pk,obj in self._get_object_list():
2018-01-22 20:01:59,602:文件 第100行中的"fakepath/wtforms/ext/sqlalchemy/fields.py" _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:文件"fakepath/wtforms/ext/sqlalchemy/fields.py",行 100,在
2018-01-22 20:01:59,603:self._object_list =列表((obj)用于查询中的obj)(文本类型(get_pk(obj)),obj)
2018-01-22 20:01:59,603:文件"fakepath/wtforms/ext/sqlalchemy/fields.py",行 189,在get_pk_from_identity
2018-01-22 20:01:59,603:cls, 键= identity_key(instance = obj)
2018-01-22 20:01:59,603: ValueError:太多值无法解包(预期2)

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问题线程上解决-

The problem is covered on the github issues thread - https://github.com/flask-admin/flask-admin/issues/1588

关于最新的sqlalchemy pip包,基本上flask-admin pip包已过时.在该特定区域,

Basically, the flask-admin pip package is out of date, in regards the latest sqlalchemy pip package. In that specific area,

cls, key = identity_key(instance=obj)

sqlalchemy现在返回3个对象,但是flask-admin只返回2个对象,因此会出现错误.

sqlalchemy is now returning 3 objects, but flask-admin is only expecting 2, hence the error.

真正的 解决方案是等到将新的flask-admin版本上传到pip之前,您还有一些选择.

The real solution for this is to wait until a new flask-admin version is uploaded to pip, until then, you've a few options.

  1. 手动进入并编辑该fields.py文件
  2. 如该发行线程中所述,将sqlalchemy限制为版本1.2.0b3.您可以在requirements.txt文件中执行此操作,也可以通过pip升级安装pip install --upgrade sqlalchemy==1.2.0b3
  3. 手动进行操作
  4. 由于此修复程序位于其github存储库中flask-admin的master分支中,因此请使用git+https://github.com/flask-admin/flask-admin的pip位置安装该版本的flask-admin.同样,您可以在requirements.txt文件中进行此操作,或者使用pip升级安装pip install --upgrade git+https://github.com/flask-admin/flask-admin.
  1. Manually go in and edit that fields.py file
  2. As detailed in that issues thread, limit sqlalchemy to version 1.2.0b3. You can do this in your requirements.txt file, or manually with a pip upgrade install, pip install --upgrade sqlalchemy==1.2.0b3
  3. As the fix is in flask-admin's master branch in their github repository, install that version of flask-admin with the pip location of git+https://github.com/flask-admin/flask-admin. Again, you do this in your requirements.txt file, or with a pip upgrade install, pip install --upgrade git+https://github.com/flask-admin/flask-admin.

我个人的喜好以及我所做的是选择3.如果您仔细阅读代码本身,那么维护人员便希望删除这行代码,无论如何,他们的处理方式会更好,并且总的来说,我更喜欢前进(flask-admin的最新版本),而不是退缩(将sqlalchemy回滚到以前的版本),并且肯定比手动编辑原始代码要好.

My personal preference, and what I've done, is option 3. If you look through the code itself, it's a line the maintainers want to remove, anyway, and how they're dealing with it is better, and in general with these things, I prefer to go forward (latest version of flask-admin) rather than holding things back (rollback sqlalchemy to a previous version), and certainly better than manually editing the raw code.

这篇关于SQL炼金术:ValueError太多值无法解包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆