SQL-alchemy: ValueError too many values to unpack?

后端 未结 2 1113
温柔的废话
温柔的废话 2020-12-16 08:33

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 th

相关标签:
2条回答
  • 2020-12-16 08:49

    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.

    0 讨论(0)
  • 2020-12-16 09:13

    I was also having this issue. I got the hacks (as described above) to work, but looking at the discussions on https://github.com/wtforms/wtforms/issues/373 and https://github.com/flask-admin/flask-admin/issues/1588, it looked like support for wtforms_sqlalchemy is not as good as wtforms_alchemy.

    So, I installed wtforms_alchemy

    pip install wtforms_alchemy 
    

    and replaced wtforms_sqlalchemy with wtform_alchemy in my project

    from wtforms_alchemy.fields import QuerySelectField 
    

    and my project worked the same.

    0 讨论(0)
提交回复
热议问题