Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 调试模式下的绑定元数据RemovedIn20警告_Python_Sqlalchemy - Fatal编程技术网

Python 调试模式下的绑定元数据RemovedIn20警告

Python 调试模式下的绑定元数据RemovedIn20警告,python,sqlalchemy,Python,Sqlalchemy,我对引擎和会话使用SQLAlchemy 1.4.0beta1和enabled future标志。通常我不会收到警告。但在调试模式下,我会收到关于2.0样式select语句的警告 My models.py: from sqlalchemy.orm import declarative_base Base = declarative_base() class Source(Base): __tablename__ = "server" id = Column(&

我对引擎和会话使用SQLAlchemy 1.4.0beta1和enabled future标志。通常我不会收到警告。但在调试模式下,我会收到关于2.0样式select语句的警告

My models.py:

from sqlalchemy.orm import declarative_base
Base = declarative_base()

class Source(Base):
    __tablename__ = "server"
    id = Column("id", Integer, primary_key=True)
    name = Column("server", String(255))
    host = Column("host", String(255))
    port = Column("port", Integer)
    username = Column("login", String(255))
    password = Column("password", String(255))
    database = Column("db", String(255))
带警告的代码:

from sqlalchemy import select
from sqlalchemy.orm import Session

with Session(engine, future=True) as session:
    stmt = select(Source).where(Source.name == source__name)
    source = session.execute(stmt).scalar()
警告本身:

/virtualenv/lib/python3.8/site-packages/sqlalchemy/sql/elements.py:489: RemovedIn20Warning: The Executable.bind attribute is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0. Bound metadata is being removed as of SQLAlchemy 2.0. (Background on SQLAlchemy 2.0 at: http://sqlalche.me/e/b8d9)
  elif self.bind:
如果我不在任何地方绑定任何元数据,为什么会有任何警告?而且,当我在调试模式下收到此警告时,我也无法到达所提到的文件行的断点

完整示例

import toml
from sqlalchemy import Column, Integer, String, select
from sqlalchemy.engine import create_engine, URL
from sqlalchemy.orm import declarative_base, Session

Base = declarative_base()

with open("config.toml") as stream:
    config = toml.load(stream)
config = config["Database"]

engine_url = URL.create(
    drivername="mysql+pymysql",
    host=config["host"],
    port=config["port"],
    username=config["username"],
    password=config["password"],
    database=config["database"],
    query={"charset": "utf8"},
)

engine = create_engine(
    engine_url,
    pool_recycle=3600,
    pool_pre_ping=True,
    encoding="utf-8",
    future=True,
)


class Source(Base):
    __tablename__ = "server"
    id = Column("id", Integer, primary_key=True)
    name = Column("server", String(255))
    host = Column("host", String(255))
    port = Column("port", Integer)
    username = Column("login", String(255))
    password = Column("password", String(255))
    database = Column("db", String(255))


with Session(engine, future=True) as session:
    stmt = select(Source).where(Source.name == "test")
    source = session.execute(stmt).scalar()

我将断点与stmt放在同一行,在与source放在同一行后出现警告。

PyCharm计算本地对象的所有属性。不推荐的
bind
恰好是其中之一

>>> stmt.bind
Traceback (most recent call last):
  File "/pycharm/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "<string>", line 2, in bind
  File "/virtualenvs/repeater-dIy575E2-py3.8/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 368, in warned
    _warn_with_version(message, version, wtype, stacklevel=3)
  File "/virtualenvs/repeater-dIy575E2-py3.8/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 41, in _warn_with_version
    warnings.warn(warn, stacklevel=stacklevel + 1)
sqlalchemy.exc.RemovedIn20Warning: The Executable.bind attribute is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0. Bound metadata is being removed as of SQLAlchemy 2.0. (Background on SQLAlchemy 2.0 at: http://sqlalche.me/e/b8d9)
>>stmt.bind
回溯(最近一次呼叫最后一次):
文件“/pycharm/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py”,第3行,在Exec中
执行官(exp、全局变量、本地变量)
文件“”,第1行,在
文件“”,第2行,处于绑定状态
文件“/virtualenvs/repeater-dIy575E2-py3.8/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py”,第368行,第2行
_使用版本警告(消息、版本、wtype、堆栈级别=3)
文件“/virtualenvs/repeater-dIy575E2-py3.8/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py”,第41行,带版本的警告
警告。警告(警告,堆栈级别=堆栈级别+1)
sqlalchemy.exc.removedIn20警告:可执行文件.bind属性在sqlalchemy的1.x系列中被视为遗留属性,将在2.0中删除。自SQLAlchemy 2.0起,绑定元数据将被删除。(SQLAlchemy 2.0背景,网址:http://sqlalche.me/e/b8d9)

FWIW,当我使用PyCharm在调试模式下运行代码时,我没有看到这样的警告;无论我选择“运行”还是“调试”,结果似乎完全相同。感谢更新。我可以用PyCharm的调试器重现这个问题。请考虑打开A,以便我们进一步研究。这看起来像是一个bug。