Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

python - SQL-alchemy: ValueError too many values to unpack?

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.

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.

Any help is appreciated!

Here is the error dump

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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 is now returning 3 objects, but flask-admin is only expecting 2, hence the error.

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. 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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...