Skip to content

OracleDialect.initialize() KeyError with Oracle 8i #2776

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Anonymous

Occasionally we've hit this KeyError with Oracle 8i:

  return Query.__iter__(self)
File 'build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py', line 2205 in __iter__
File 'build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py', line 2218 in _execute_and_instances
File 'build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py', line 2209 in _connection_from_session
File 'build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py', line 732 in connection
File 'build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py', line 736 in _connection_for_bind
File 'build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py', line 266 in _connection_for_bind
File 'build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py', line 2476 in contextual_connect
File 'build/bdist.linux-x86_64/egg/sqlalchemy/pool.py', line 224 in connect
File 'build/bdist.linux-x86_64/egg/sqlalchemy/pool.py', line 387 in __init__
File 'build/bdist.linux-x86_64/egg/sqlalchemy/pool.py', line 739 in _do_get
File 'build/bdist.linux-x86_64/egg/sqlalchemy/pool.py', line 188 in _create_connection
File 'build/bdist.linux-x86_64/egg/sqlalchemy/pool.py', line 273 in __init__
File 'build/bdist.linux-x86_64/egg/sqlalchemy/event.py', line 282 in exec_once
File 'build/bdist.linux-x86_64/egg/sqlalchemy/event.py', line 291 in __call__
File 'build/bdist.linux-x86_64/egg/sqlalchemy/engine/strategies.py', line 167 in first_connect
File 'build/bdist.linux-x86_64/egg/sqlalchemy/dialects/oracle/cx_oracle.py', line 564 in initialize
File 'build/bdist.linux-x86_64/egg/sqlalchemy/dialects/oracle/base.py', line 696 in initialize
KeyError: <class 'sqlalchemy.types.Interval'>

The initialize() code is here:

    def initialize(self, connection):
        super(OracleDialect, self).initialize(connection)
        self.implicit_returning = self.__dict__.get(
                                    'implicit_returning',
                                    self.server_version_info > (10, )
                                    )

        if self._is_oracle_8:
            self.colspecs = self.colspecs.copy()
            self.colspecs.pop(sqltypes.Interval)
            self.use_ansi = False

Question: is there a legitimate reason to be inside initialize() more than once? Apparently that is what has happened here because the .pop(sqltypes.Interval) has already been run on self.colspecs.

I'm guessing the real problem is with the connection pool or something and sqlalchemy thinks it needs to initialize this since it isn't properly connected?


Attachments: 2776.patch | 2776_test.patch

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2013

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

Note that this was preceded by OperationalError: (OperationalError) ORA-03113: end-of-file on communication channel, but the question is: does SQLAlchemy usually have no problem reconnecting and this is an Oracle 8i problem because of the pop code above?

''I've answered my question: "Yes, usually SQLAlchemy will reconnect and invoke initialize() a subsequent time."''

sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2013

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

Possible patch

sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2013

@sqlalchemy-bot
CollaboratorAuthor

Changes by Anonymous:

  • attached file 2776.patch
sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2013

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

intiialize() on a dialect shouldn't be called more than once, so if this is a side effect of engine/pool recycle, I'd want to look into that at a more fundamental level.

sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2013

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • added labels: high priority
  • set milestone to "0.8.xx"
sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2013

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

Note that I ran this test on an Oracle 10 database and bounced the database. The same dialect object's initialize() ''was'' invoked a subsequent time and it continued working fine thereafter. So apparently, this works this way "normally" but the oracle 8 clause is messing it up:

[Jul 08 22:52:39 2013](Mon) [error](error) ##### initialize for <sqlalchemy.dialects.oracle.cx_oracle.OracleDialect_cx_oracle object at 0x2aefaf22d590> (47208923846032)
[Jul 08 22:54:02 2013](Mon) [error](error) ##### initialize for <sqlalchemy.dialects.oracle.cx_oracle.OracleDialect_cx_oracle object at 0x2aefaf22d590> (47208923846032)
sqlalchemy-bot

sqlalchemy-bot commented on Jul 9, 2013

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

i've attached a unit test for this.

sqlalchemy-bot

sqlalchemy-bot commented on Jul 11, 2013

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

let me know if i could/should help on this ticket.

sqlalchemy-bot

sqlalchemy-bot commented on Jul 11, 2013

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

OK...well should be resolved:

9a95a39 0.8.3

fd55be0 master

sqlalchemy-bot

sqlalchemy-bot commented on Jul 11, 2013

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
sqlalchemy-bot

sqlalchemy-bot commented on Jul 12, 2013

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

Certainly stops Dialect.initialize() from being invoked again, thanks!

P.S. Not functionally important, but in lib/sqlalchemy/util/langhelpers.py you stuck the def only_once() decorator in between the chop_traceback() definition and its constants:

_SQLA_RE = re.compile(r'sqlalchemy/([a-z_](a-z_)+/){0,2}[a-z_](a-z_)+\.py')
_UNITTEST_RE = re.compile(r'unit(?:2|test2?/)')
def chop_traceback(tb, exclude_prefix=_UNITTEST_RE, exclude_suffix=_SQLA_RE):
...
sqlalchemy-bot

sqlalchemy-bot commented on Jul 12, 2013

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

yup, 269a166 1e332e0, thanks

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          OracleDialect.initialize() KeyError with Oracle 8i · Issue #2776 · sqlalchemy/sqlalchemy