flask_sqlalchemy:将__setattr__设置为DefaultMeta时出错 [英] flask_sqlalchemy: error with `__setattr__` to `DefaultMeta`

查看:175
本文介绍了flask_sqlalchemy:将__setattr__设置为DefaultMeta时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重新构建Docker映像后,我开始出现以下错误:

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

尽管我也遇到了版本1.3.172.4.1的错误.

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

推荐答案

经过一些实验,看来问题出在python:3.8.3-slimpython:3.8.4-slim之间.

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 …

如果不是这样的话

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

此错误/修复程序似乎是导致此问题的原因: https://bugs.python.org/issue39960

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

这篇关于flask_sqlalchemy:将__setattr__设置为DefaultMeta时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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