[Sqlalchemy-tickets] Issue #3123: mysql reflection on python-2.6 causes error (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: barnabas79 <iss...@bi...> - 2014-07-11 18:31:15
|
New issue 3123: mysql reflection on python-2.6 causes error https://bitbucket.org/zzzeek/sqlalchemy/issue/3123/mysql-reflection-on-python-26-causes-error barnabas79: The essential problem is that mysql seems to return some table names as unicode, and in python 2.6, you can't use unicode as keys in a dict that you're unpacking for function kwargs - ie, in python 2.6, this: ``` #!python def foo(**kwargs): print kwargs foo(**{u'thing':1}) ``` will raise an error: ``` #!python TypeError: foo() keywords must be strings ``` To replicate: * Set up a mysql server * On fedora 19, I just did: * yum install mysql-server * service mysqld start * Using **python-2.6**, Run the following code (assuming you're connecting to the server running on the same machine, and that there's a database called "test", which should exist by default): ``` #!python from sqlalchemy import create_engine from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey # connect to the "test" database, which should be set up by default DEFAULT_DB_HOST = 'sv-db05' engine = create_engine("mysql+mysqldb://127.0.0.1/test", echo=True) # Set up a basic table metadata = MetaData() users = Table( 'users', metadata, Column('id', Integer, primary_key=True), Column('name', String(255)), ) metadata.create_all(engine) # now reflect.. metadata2 = MetaData() metadata2.reflect(engine, only=['users']) ``` This should raise this error: ``` #!python Traceback (most recent call last): File "<stdin>", line 22, in <module> metadata2.reflect(engine, only=['users']) File "./sqlalchemy/lib/sqlalchemy/sql/schema.py", line 3288, in reflect Table(name, self, **reflect_opts) File "./sqlalchemy/lib/sqlalchemy/sql/schema.py", line 353, in __new__ table._init(name, metadata, *args, **kw) File "./sqlalchemy/lib/sqlalchemy/sql/schema.py", line 426, in _init self._autoload(metadata, autoload_with, include_columns) File "./sqlalchemy/lib/sqlalchemy/sql/schema.py", line 438, in _autoload self, include_columns, exclude_columns File "./sqlalchemy/lib/sqlalchemy/engine/base.py", line 1239, in run_callable return callable_(self, *args, **kwargs) File "./sqlalchemy/lib/sqlalchemy/engine/default.py", line 356, in reflecttable return insp.reflecttable(table, include_columns, exclude_columns) File "./sqlalchemy/lib/sqlalchemy/engine/reflection.py", line 474, in reflecttable for col_d in self.get_columns(table_name, schema, **table.dialect_kwargs): TypeError: get_columns() keywords must be strings ``` |