Hi all,

I have run into a problem with SQLAlchemy r6472 (svn trunk) which might
be a bug.

I will not bore you with the details of the importer tool I am writing,
but rather enclosed a small script that exemplifies the problem.

--- typeerr.py ---
from sqlalchemy import *
from sqlalchemy.orm import *


psql_engine = create_engine(
    'postgresql+psycopg2://babilen:ax8xwymferm...@localhost/typeerr_bug')
metadata = MetaData(bind=psql_engine)

ll_t = Table(u'langlinks', metadata,
             Column(u'll_from', Integer,
                    nullable=False,
                    server_default='0',
                   ),
             Column(u'll_lang', Unicode(20),
                    nullable=False,
                    server_default='',
                   ),
             Column(u'll_title', Unicode(255),
                    nullable=False,
                    server_default='',
                   )
            )

print u'Create table....'
pl_t.create()
print u'Table created....'

conn = psql_engine.connect()

# here be dragons
file_content = open('insert_stmt.sql', 'rb').read()
insert_stmt = file_content.decode('utf8')
conn.execute(insert_stmt)
--- snip ---

The program fails with the following exception:

--- Exception with minor editing (path) ---
$ python typeerr.py 
Create table....
Table created....
Traceback (most recent call last):
  File "typeerr.py", line 33, in <module>
    conn.execute(insert_stmt)
  File "../lib/sqlalchemy/engine/base.py", line 975, in execute
    return Connection.executors[c](self, object, multiparams, params)
  File "../lib/sqlalchemy/engine/base.py", line 1051, in _execute_text
    return self.__execute_context(context)
  File "../lib/sqlalchemy/engine/base.py", line 1060, in __execute_context
    self._cursor_execute(context.cursor, context.statement, 
context.parameters[0], context=context)
  File "../lib/sqlalchemy/engine/base.py", line 1120, in _cursor_execute
    self.dialect.do_execute(cursor, statement, parameters, context=context)
  File "../lib/sqlalchemy/engine/default.py", line 181, in do_execute
    cursor.execute(statement, parameters)
TypeError: 'dict' object does not support indexing
--- snip ---

If you want to test the behaviour yourself you can download 'insert_stmt.sql' 
from:

    http://www.cl.uni-heidelberg.de/~wentland/insert_stmt.sql

I would like to note that piping the insert statement directly into psql works 
fine:

--- snip ---
$ psql -d typeerr_bug < insert_stmt.sql 
INSERT 0 32173
--- snip ---

What is causing this behaviour and even more importantly: What can I do
about it?

kind regards

    Wolodja Wentland

Attachment: signature.asc
Description: Digital signature

Reply via email to