gpt4 book ai didi

python - pg8000 和 sqlalchemy 查询会引发异常,但仅有时发生

转载 作者:太空宇宙 更新时间:2023-11-03 18:19:17 27 4
gpt4 key购买 nike

oSame = oSession.query(UserAction).filter_by(tablename=self.tablename).filter_by(isn=self.isn).filter_by(time_stamp=self.time_stamp).filter_by(command=self.command).filter_by(command_type=self.command_type).filter_by(username=self.username).first()

引发异常:

NotSupportedError: type oid 705 not mapped to py type

完整的回溯包含在最后......

所以我想我应该使用排除法来找出哪一列是奇怪的。我想出了这个:

    try:
oSame = oSession.query(UserAction).filter_by(tablename=self.tablename).filter_by(isn=self.isn).filter_by(time_stamp=self.time_stamp).filter_by(command=self.command).filter_by(command_type=self.command_type).filter_by(username=self.username).first()
except:
oEx = oSession.query(UserAction).filter_by(tablename=self.tablename).filter_by(isn=self.isn).filter_by(time_stamp=self.time_stamp).filter_by(command=self.command).filter_by(command_type=self.command_type).filter_by(username=self.username).first()
raise Exception(oEx)

这引发了异常:

Exception: <adabas_converter.models.UserAction object at 0x27c7f50>

请注意,oSame 使用的表达式与 oEX 完全相同!这看起来很疯狂。

try:
do_stuff() <----raises exception
except:
do_stuff() <----executes just fine!

所以我的问题是:为什么查询在 except 子句中成功执行,但在原始代码中却失败了?

此外,如果我将驱动程序更换为 psycopg2,那么所有奇怪的事情都会停止。

原始回溯:

File "/home/criticalid/programs/adabas_converter/models.py", line 53, in __init__
oSame = oSession.query(UserAction).filter_by(tablename=self.tablename).filter_by(isn=self.isn).filter_by(time_stamp=self.time_stamp).filter_by(command=self.command).filter_by(command_type=self.command_type).filter_by(username=self.username).first()
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2333, in first
ret = list(self[0:1])
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2200, in __getitem__
return list(res)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2404, in __iter__
return self._execute_and_instances(context)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2417, in _execute_and_instances
close_with_result=True)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2408, in _connection_from_session
**kw)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/session.py", line 843, in connection
close_with_result=close_with_result)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/session.py", line 847, in _connection_for_bind
return self.transaction._connection_for_bind(engine)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/orm/session.py", line 315, in _connection_for_bind
conn = bind.contextual_connect()
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1729, in contextual_connect
self.pool.connect(),
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/pool.py", line 332, in connect
return _ConnectionFairy._checkout(self)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/pool.py", line 626, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/pool.py", line 433, in checkout
rec = pool._do_get()
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/pool.py", line 945, in _do_get
return self._create_connection()
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/pool.py", line 278, in _create_connection
return _ConnectionRecord(self)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/pool.py", line 409, in __init__
exec_once(self.connection, self)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/event/attr.py", line 247, in exec_once
self(*args, **kw)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/event/attr.py", line 257, in __call__
fn(*args, **kw)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", line 1203, in go
return once_fn(*arg, **kw)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 165, in first_connect
dialect.initialize(c)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/dialects/postgresql/base.py", line 1560, in initialize
super(PGDialect, self).initialize(connection)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/engine/default.py", line 250, in initialize
self._check_unicode_description(connection):
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.4-py2.7-linux-x86_64.egg/sqlalchemy/engine/default.py", line 335, in _check_unicode_description
]).compile(dialect=self)
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/dbapi.py", line 243, in _fn
return fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/dbapi.py", line 314, in execute
self._execute(operation, args)
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/dbapi.py", line 319, in _execute
self.cursor.execute(new_query, *new_args)
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/interface.py", line 304, in execute
self._stmt.execute(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/interface.py", line 139, in execute
self._row_desc, cmd = self.c.bind(self._portal_name, self._statement_name, args, self._parse_row_desc, kwargs.get("stream"))
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/protocol.py", line 913, in _fn
return fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/protocol.py", line 1082, in bind
output_fc = [types.py_type_info(f) for f in row_desc.fields]
File "/usr/local/lib/python2.7/dist-packages/pg8000-1.08-py2.7.egg/pg8000/types.py", line 162, in py_type_info
raise NotSupportedError("type oid %r not mapped to py type" % type_oid)
NotSupportedError: type oid 705 not mapped to py type

最佳答案

从堆栈跟踪来看,您使用的是 pg8000 版本 1.08,但最新版本是 pg8000-1.9.10 。如果升级后仍有问题,请告诉我。

关于python - pg8000 和 sqlalchemy 查询会引发异常,但仅有时发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24429387/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com