flask_sqlalchemy: error with `__setattr__` to `DefaultMeta`

∥☆過路亽.° 提交于 2020-08-19 11:23:58

问题


After re-building a Docker image, I've started to get the following error:

$ docker run --rm -it python:3.8-slim /bin/bash
...
$ pip install flask_sqlalchemy
...
$ python -c "from flask_sqlalchemy import SQLAlchemy; SQLAlchemy()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 715, in __init__
    self.Model = self.make_declarative_base(model_class, metadata)
  File "/usr/local/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 797, in make_declarative_base
    model.query_class = self.Query
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/ext/declarative/api.py", line 79, in __setattr__
    _add_attribute(cls, key, value)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 802, in _add_attribute
    type.__setattr__(cls, key, value)
TypeError: can't apply this __setattr__ to DefaultMeta object

The versions of the specific packages involved:

python -c "import sqlalchemy, flask_sqlalchemy; print(sqlalchemy.__version__, flask_sqlalchemy.__version__)"
1.3.18 # sqlalchemy
2.4.3 # flask_sqlalchemy

Although I've also experienced the error with versions 1.3.17 and 2.4.1.


回答1:


After some experimentation, it seems like the issue is due to some change between python:3.8.3-slim and python:3.8.4-slim.

To reproduce, notice that this works:

$ docker run --rm -it python:3.8.3-slim …

Where this does not:

docker run --rm -it python:3.8.4-slim …

It looks like this bug/fix is the cause of the issue: https://bugs.python.org/issue39960



来源:https://stackoverflow.com/questions/62896860/flask-sqlalchemy-error-with-setattr-to-defaultmeta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!