ptahproject/ptah — Issue #116: MySQL Compatibility
Author: bitmonk
Created: 2011-12-30 23:08:45+00:00
State: open

I've been trying to port my Ptah application to MySQL, and I've run into some trouble where Unicode fields with no length trigger an error in MySQL:

sqlalchemy.exc.InvalidRequestError: VARCHAR requires a length on dialect mysql

My application is based on ptah_simpleauth, so rather than complicate this discussion with the details of my app, I've reproduced it with HEAD of ptah and ptah_simpleauth, simply by changing the sqlalchemy uri in settings.ini :

```
justin@dev-ops:~/py27sqla/examples/ptah_simpleauth$ ../../bin/pserve settings.ini
Traceback (most recent call last):
File "../../bin/pserve", line 8, in
load_entry_point('pyramid==1.3a3', 'console_scripts', 'pserve')()
File "/home/justin/py27sqla/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/scripts/pserve.py", line 32, in main
return command.run()
File "/home/justin/py27sqla/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/scripts/pserve.py", line 275, in run
relative_to=base, global_conf=vars)
File "/home/justin/py27sqla/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/scripts/pserve.py", line 303, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/home/justin/py27sqla/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/home/justin/py27sqla/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/home/justin/py27sqla/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/util.py", line 56, in fix_call
val = callable(*args, **kw)
File "/home/justin/py27sqla/examples/ptah_simpleauth/ptah_simpleauth/app.py", line 47, in main
Base.metadata.create_all()
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/schema.py", line 2515, in create_all
tables=tables)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2234, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1904, in _run_visitor
**kwargs).traverse_single(element)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 86, in traverse_single
return meth(obj, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/ddl.py", line 67, in visit_metadata
self.traverse_single(table, create_ok=True)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 86, in traverse_single
return meth(obj, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/ddl.py", line 86, in visit_table
self.connection.execute(schema.CreateTable(table))
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1405, in execute
params)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1490, in _execute_ddl
compiled = ddl.compile(dialect=dialect)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/sql/expression.py", line 1722, in compile
return self._compiler(dialect, bind=bind, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/schema.py", line 2852, in _compiler
return dialect.ddl_compiler(dialect, self, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 699, in __init__
self.string = self.process(self.statement)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 718, in process
return obj._compiler_dispatch(self, **kwargs)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 59, in _compiler_dispatch
return getter(visitor)(self, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 1377, in visit_create_table
not first_pk
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 1367, in get_column_specification
self.dialect.type_compiler.process(column.type)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 764, in process
return type_._compiler_dispatch(self)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 59, in _compiler_dispatch
return getter(visitor)(self, **kw)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 1702, in visit_unicode
return self.visit_VARCHAR(type_)
File "/home/justin/py27sqla/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 1654, in visit_VARCHAR
self.dialect.name)
sqlalchemy.exc.InvalidRequestError: VARCHAR requires a length on dialect mysql
```

I was able to get around this by changing Unicode and String types with no length in my code / ptah_simpleauth and ptah, at least in the past couple of days, but I think that today I'm running into this even after having done so with all incidences of sqla.Unicode and sqla.String that I could find.