pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.8k stars 1.58k forks source link

ValueError: too many values to unpack #1588

Closed SantosJMM closed 6 years ago

SantosJMM commented 6 years ago

Hi, I'm starting to test admin flask and I started with your tasks and I get this error ---> ValueError: too many values to unpack

ghost commented 6 years ago

same here, code from example

maxtortime commented 6 years ago
File "/usr/local/lib/python3.5/site-packages/flask_admin/contrib/sqla/fields.py", 
line 299, in get_pk_from_identity
cls, key = identity_key(instance=obj)
ValueError: too many values to unpack (expected 2)

I also shown this issue when I click edit button one of my records.

I think that 197896a commit resolves problem.

doobeh commented 6 years ago

Quick fix is adding sqlalchemy==1.2.0b3 to your requirements.txt until Flask-Admin pushes a new release that addresses the issue to PyPi. There are a few closed issues that relate to this, it might be worth keeping this one open until a simple pip install flask-admin install solves the problem.

maxtortime commented 6 years ago

@doobeh Thanks. I resolved the problem from your instructions.

knrdl commented 6 years ago

Another possible workaround (doesn't require special sqlalchemy version): In "/usr/local/lib/python3.5/site-packages/flask_admin/contrib/sqla/fields.py": Replace line 299: cls, key = identity_key(instance=obj) With this: cls, key, *foobar = identity_key(instance=obj)

The extra arguments (total of 3 args in my case) are assigned to foobar, so the process won't crash

HitDaCa commented 6 years ago

I can see this issue has already been fixed and merged into master. Question is probably when the next update (1.5.1 ?) will be release.

seaders commented 6 years ago

Given that it's fixed here, in master, instead of freezing sqlalchemy, you can pip upgrade install directly from this repo,

 pip install --upgrade git+https://github.com/flask-admin/flask-admin

That's my preference, rather than holding another place back (that's given me other performance improvements that I had been asking for / waiting on).

jacobsvante commented 6 years ago

@mrjoes Any chance for a 1.5.1 with this fix? 😀

GendoIkari commented 6 years ago

Without this fix it is a broken release...

HitDaCa commented 6 years ago

@seaders just referencing a master branch is definitely not an option for many people on production servers.

seaders commented 6 years ago

@HitDaCa I didn't recommend people do that, I gave it as an option, and stated it as my preference. If you / other people do, or don't want to do that on your production servers, that's your choice.

Fisherworks commented 6 years ago

@seaders yes I encountered this issue (with newly updated sqlalchemy version) which just get reported from developer - the admin page not working, and your install --upgrade <git repo> saved my day (both on production and test server). perhaps I could do something like install --upgrade Flask-Admin little later (I don't know when), but right now downgrade sqlalchemy version (without bug from sqlalchemy) is definitely the last thing I would do. thanks for this.

danidee10 commented 6 years ago

I'm also affected by this issue. I followed @doobeh suggestion

mush42 commented 6 years ago

Starlit CMS is also effected by this one. Installed flask_admin from the master branch. Looks like this is the right time for a minor release.

cnstlungu commented 6 years ago

Was affected by the same issue. Solved by upgrading as @seaders suggested.

seaders commented 6 years ago

I have now been affected by this issue in other areas (wtforms in their "deprected" ext/sqlalchemy area, and the new wtforms-alchemy) so if you're like me, and it's not an option to upgrade all of these to their github packages, my chosen option is now to limit sqlalchemy to 1.2.0b3 as described by @doobeh.

Bit of a big mess now this, unfortunately.

jpiorkowski commented 6 years ago

For those not keen on pinning beta releases (and who don't need features from sqlalchemy 1.2 branch), pinning sqlalchemy==1.1.6 also appears to work around this issue. 1.1.16 was released on 2018-02-16 and is thus newer than 1.2.0b3 (2017-10-13).

mrjoes commented 6 years ago

The fix was merged into the master and is going to be released in the next version that should be released later this week.

idealisconsultingbe commented 6 years ago

Solved with a monkey patch for me...

# -*- coding: utf-8 -*-
from flask_admin.contrib.sqla import fields
from flask_admin._compat import text_type
from sqlalchemy.orm.util import identity_key

def get_pk_from_identity(obj):
    res = identity_key(instance=obj)
    cls, key = res[0], res[1]
    return u':'.join(text_type(x) for x in key)

fields.get_pk_from_identity = get_pk_from_identity
seaders commented 6 years ago

@idealisconsultingbe Yeah, I needed to go back up to the latest SQLAlchemy version, and as I said was getting messed around with the other incompatible functions in other packages, so I've gone with your solution.

For completeness, here's the same monkeypatch, but also working on wtforms areas,

# -*- coding: utf-8 -*-
from sqlalchemy.orm.util import identity_key
from flask_admin.contrib.sqla.fields import text_type

from flask_admin.contrib.sqla import fields
from wtforms_alchemy import fields as wtf_fields
from wtforms.ext.sqlalchemy import fields as wtfs_fields

def get_pk_from_identity(obj):
    res = identity_key(instance=obj)
    cls, key = res[0], res[1]
    return text_type(':'.join(text_type(x) for x in key))

fields.get_pk_from_identity = get_pk_from_identity
wtf_fields.get_pk_from_identity = get_pk_from_identity
wtfs_fields.get_pk_from_identity = get_pk_from_identity

#
tmorriso commented 6 years ago

Has this issue been fixed? The comment says it was closed in February, but I am still experiencing the issue. I have tried updating flask_admin.

iamsk commented 5 years ago

Has this issue been fixed? The comment says it was closed in February, but I am still experiencing the issue. I have tried updating flask_admin.

Because the latest docker image use Flask-Admin==1.4.2, we need update the re:dash code.