Hi,

I'm getting a strange error in sqlalchemy/engine/base.py when I try to
use a mysql table with more than 6 columns and serve a page using
mod_wsgi.

Here's a simple dispatch.wsgi file that demonstrates the problem:

===============================================================================
from sqlalchemy import create_engine
engine = create_engine('mysql://user:passwd@db/table', echo=True)

from sqlalchemy import Table, Column, Integer, String, SmallInteger,
MetaData, ForeignKey
metadata = MetaData()

Users_table = Table('users', metadata,
    Column('id', String(10), nullable=False, default='',
primary_key=True),
    Column('name', String(100)),
    Column('password', String(20), default=''),
    Column('extracol1', SmallInteger(4)),
    Column('extracol2', SmallInteger(4)),
    Column('extracol3', String(255)),
    Column('extracol4', SmallInteger(4))
)

metadata.create_all(engine)

class User(object):
    def __init__(self):
        pass

from sqlalchemy.orm import mapper
mapper(User, Users_table)

from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine)

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    newUser = User()
    newUser.id = 'test'

    session = Session()
    session.add(newUser)
    session.commit()

    user = session.query(User).filter(User.id=='test').one()

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]
===============================================================================

When I try to view the page I get this error:
===============================================================================
[Wed Jun 08 13:40:23 2011] [error] [client ] mod_wsgi (pid=2546):
Exception occurred processing WSGI script '/home/web/TA/
dispatch.wsgi'.

...
[Wed Jun 08 13:40:23 2011] [error] [client ]   File "/opt/python-2.7.1/
lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7-linux-x86_64.egg/
sqlalchemy/engine/base.py", line 2673, in _init_metadata
[Wed Jun 08 13:40:23 2011] [error] [client ]     self._metadata =
ResultMetaData(self, metadata)
[Wed Jun 08 13:40:23 2011] [error] [client ]   File "/opt/python-2.7.1/
lib/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7-linux-x86_64.egg/
sqlalchemy/engine/base.py", line 2533, in __init__
[Wed Jun 08 13:40:23 2011] [error] [client ]     name, obj, type_ =
context.result_map[colname.lower()]
[Wed Jun 08 13:40:23 2011] [error] [client ] AttributeError:
'NoneType' object has no attribute 'lower'
===============================================================================

The table is created correctly and the user is added, but when the
select statement is issued, I get this error.  It appears that the
metadata could be wrong(?) since the tuple containing 'None' is what
seems to be causing the error.

===============================================================================
[Wed Jun 08 13:40:23 2011] [error] 2011-06-08 13:40:23,898 INFO
sqlalchemy.engine.base.Engine SELECT users.id AS users_id, users.name
AS users_name, users.password AS users_password, users.flagid AS
users_flagid, users.prefix AS users_prefix, users.config AS
users_config, users.view AS users_view
[Wed Jun 08 13:40:23 2011] [error] FROM users
[Wed Jun 08 13:40:23 2011] [error] WHERE users.id = %s
[Wed Jun 08 13:40:23 2011] [error] 2011-06-08 13:40:23,898 INFO
sqlalchemy.engine.base.Engine ('test',)
[Wed Jun 08 13:40:23 2011] [error] (('users_id', 253, 5, 10, 10, 0,
0), ('name', 22648936, 10, 0, 0, 253, 1), ('users', 22649016, 5, 14,
14, 22649000, 1), ('users', 22649040, 7, 5, 5, 22649072, 1),
('dh_test', 22649104, 0, 7, 7, 22649096, 1), ('def', 22649144, 0, 0,
0, 22649160, 1), (None, 22648832, 2, 0, 0, 1919251317, 0))
[Wed Jun 08 13:40:23 2011] [error] *** 0 users_id 253
[Wed Jun 08 13:40:23 2011] [error] *** 1 name 22648936
[Wed Jun 08 13:40:23 2011] [error] *** 2 users 22649016
[Wed Jun 08 13:40:23 2011] [error] *** 3 users 22649040
[Wed Jun 08 13:40:23 2011] [error] *** 4 table 22649104
[Wed Jun 08 13:40:23 2011] [error] *** 5 def 22649144
[Wed Jun 08 13:40:23 2011] [error] *** 6 None 22648832
===============================================================================

If I delete one of the columns in the schema definition (so there are
only 6 columns) I don't get this error; the query executes
successfully and 'Hello World!' is printed.  I've tried my real
application with SQLite and didn't encounter this error.  I also don't
run into this error if I serve the application using paster.

Thanks for any help,

Doug

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to