SQLAlchemy的sqlite create_engine抛出异常

huangapple go评论62阅读模式
英文:

SQLAlchemy sqlite create_engine throws an exception

问题

我在我的单元测试中使用了一个SQLite数据库,最近尝试升级到SQLAlchemy的2.0.4版本,但这导致了创建测试SQLite数据库的问题:

engine = sa.create_engine('sqlite://')
sqlalchemy_connection = engine.connect()
dbapi_connection = <sqlite3.Connection object at 0x7f9ea0ba6570>

def set_regexp(dbapi_connection):
    dbapi_connection.create_function(
        "regexp", 2, regexp, **create_func_kw
    )
E       TypeError: 函数最多接受3个参数提供了4个

在1.4.16版本下运行正常,有人有任何想法吗?(看起来问题出在create_engine上,但与迁移指南中的示例类似)

英文:

I use an sqlite db for my unittests and tried to update to the 2.0.4 version of SQLAlchemy recently and this leads to an issue with creating a test sqlite DB:

    engine = sa.create_engine(&#39;sqlite://&#39;)
    sqlalchemy_connection = engine.connect()
dbapi_connection = &lt;sqlite3.Connection object at 0x7f9ea0ba6570&gt;

    def set_regexp(dbapi_connection):
&gt;       dbapi_connection.create_function(
            &quot;regexp&quot;, 2, regexp, **create_func_kw
        )
E       TypeError: function takes at most 3 arguments (4 given)

Works fine with 1.4.16, anyone got any ideas? (the create_engine semms to be at fault, but looks similar to the examples in the migration guide)

答案1

得分: 0

这确实是一个较旧的sqlite版本(例如,与rhel 7捆绑使用的版本)与SQLAlchemy 2.0不兼容的问题。有关完整讨论,请参见:https://github.com/sqlalchemy/sqlalchemy/discussions/9379

英文:

This is indeed an incompatibility issue of a quite old sqlite version (shipped with rhel 7 for example) and sqlalchemy 2.0, for the complete discussion, see: https://github.com/sqlalchemy/sqlalchemy/discussions/9379

huangapple
  • 本文由 发表于 2023年2月27日 14:55:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577492.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定