在 MS SQL 中添加记录后 SqlAlchemy 挂起

发布于 2024-09-02 00:55:37 字数 2862 浏览 1 评论 0原文

我正在 Jython 上运行 SQLAlchemy,并尝试使用带有 Windows 身份验证的 jTDS 连接到 MS SQL 数据库。我可以很好地查询和删除,但是当我尝试插入新值时,它会在提交时挂起。

print 'before add'
session.add(newVal)
print 'after add'
session.commit()
print 'after commit'

我看到前两个打印语句,但没有看到最后一个。我的 CPU 已达到极限,我什至无法使用 MS SQL Management Studio 直接查询表。当我终止 Jython java 进程时,我可以再次查询,但尚未添加新值。

奇怪的是,我可以使用 SQL 命令直接插入值:

insert_sql = "INSERT INTO my_table (my_value) VALUES ('test_value')"
session.execute(insert_sql)
session.commit()

知道我做错了什么吗?

这是一个缩短的堆栈跟踪:

"MainThread" prio=6 tid=0x0000000000def000 nid=0x528 runnable [0x0000000002c3d000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.Throwable.fillInStackTrace(Native Method)
    - locked <0x0000000021e98880> (a org.python.core.PyException)
    at org.python.core.PyException.fillInStackTrace(PyException.java:70)
    at java.lang.Throwable.<init>(Throwable.java:181)
    at java.lang.Exception.<init>(Unknown Source)
    at java.lang.RuntimeException.<init>(Unknown Source)
    at org.python.core.PyException.<init>(PyException.java:46)
    at org.python.core.PyException.<init>(PyException.java:43)
    at org.python.core.PyException.<init>(PyException.java:61)
    at org.python.core.Py.AttributeError(Py.java:145)
    at org.python.core.PyObject.noAttributeError(PyObject.java:936)
    at org.python.core.PyObject.object___getattribute__(PyObject.java:3694)
    at org.python.core.PyObject$object___getattribute___exposer.__call__(Unknown Source)
    at org.python.core.PyObjectDerived.__findattr_ex__(PyObjectDerived.java:993)
    at org.python.core.PyObject.__getattr__(PyObject.java:929)
    at sqlalchemy.dialects.mssql.zxjdbc$py.post_exec$3(C:\Users\pchavez\bin\netbeans\NetBeans 6.7 Python EA2\python1\jython-2.5\Lib\site-packages\sqlalchemy\dialects\mssql\zxjdbc.py:52)
    at sqlalchemy.dialects.mssql.zxjdbc$py.call_function(C:\Users\pchavez\bin\netbeans\NetBeans 6.7 Python EA2\python1\jython-2.5\Lib\site-packages\sqlalchemy\dialects\mssql\zxjdbc.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:165)

    ...

    at org.python.pycode._pyx0.f$0(C:\Users\pchavez\sqltool\src\db\sqltest.py:99)
    at org.python.pycode._pyx0.call_function(C:\Users\pchavez\sqltool\src\db\sqltest.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:165)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1197)
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:166)
    at org.python.util.jython.run(jython.java:229)
    at org.python.util.jython.main(jython.java:117)

据我所知,这是 sqlalchemy.dialects.mssql.zxjdbc 模块中的无限循环:

def post_exec(self):
    if self._embedded_scope_identity:
        while True:
            ...

I'm running SQLAlchemy on Jython and trying to connect to a MS SQL database using jTDS with windows authentication. I can query and delete just fine but when I try to insert new values it will hang when I commit.

print 'before add'
session.add(newVal)
print 'after add'
session.commit()
print 'after commit'

I see the first two print statements but not the last. My CPU maxes out and I can't even query the table directly using the MS SQL Management Studio. When I kill the Jython java process I can query again but the new values haven't been added.

Strangely enough I can insert values directly using an SQL command:

insert_sql = "INSERT INTO my_table (my_value) VALUES ('test_value')"
session.execute(insert_sql)
session.commit()

Any ideas what I'm doing wrong?

Here is a shortened stack trace:

"MainThread" prio=6 tid=0x0000000000def000 nid=0x528 runnable [0x0000000002c3d000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.Throwable.fillInStackTrace(Native Method)
    - locked <0x0000000021e98880> (a org.python.core.PyException)
    at org.python.core.PyException.fillInStackTrace(PyException.java:70)
    at java.lang.Throwable.<init>(Throwable.java:181)
    at java.lang.Exception.<init>(Unknown Source)
    at java.lang.RuntimeException.<init>(Unknown Source)
    at org.python.core.PyException.<init>(PyException.java:46)
    at org.python.core.PyException.<init>(PyException.java:43)
    at org.python.core.PyException.<init>(PyException.java:61)
    at org.python.core.Py.AttributeError(Py.java:145)
    at org.python.core.PyObject.noAttributeError(PyObject.java:936)
    at org.python.core.PyObject.object___getattribute__(PyObject.java:3694)
    at org.python.core.PyObject$object___getattribute___exposer.__call__(Unknown Source)
    at org.python.core.PyObjectDerived.__findattr_ex__(PyObjectDerived.java:993)
    at org.python.core.PyObject.__getattr__(PyObject.java:929)
    at sqlalchemy.dialects.mssql.zxjdbc$py.post_exec$3(C:\Users\pchavez\bin\netbeans\NetBeans 6.7 Python EA2\python1\jython-2.5\Lib\site-packages\sqlalchemy\dialects\mssql\zxjdbc.py:52)
    at sqlalchemy.dialects.mssql.zxjdbc$py.call_function(C:\Users\pchavez\bin\netbeans\NetBeans 6.7 Python EA2\python1\jython-2.5\Lib\site-packages\sqlalchemy\dialects\mssql\zxjdbc.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:165)

    ...

    at org.python.pycode._pyx0.f$0(C:\Users\pchavez\sqltool\src\db\sqltest.py:99)
    at org.python.pycode._pyx0.call_function(C:\Users\pchavez\sqltool\src\db\sqltest.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:165)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1197)
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:166)
    at org.python.util.jython.run(jython.java:229)
    at org.python.util.jython.main(jython.java:117)

From what I can tell it is an infinate loop in the sqlalchemy.dialects.mssql.zxjdbc module:

def post_exec(self):
    if self._embedded_scope_identity:
        while True:
            ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文