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


完整的(ish)追溯包括在末尾...

因此,我想我会使用消除的方法来找出哪个列很奇怪。我想出了这个:

    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/

10-13 05:40