1. Michael Bayer
  2. sqlalchemy

Issues

Issue #1909 new

reflection issue with mysql, url with no schema failure

Chris Withers
created an issue

code:

 from sqlalchemy import create_engine,MetaData
 engine = create_engine('mysql://user:pass@server')
 metadata = MetaData(engine,reflect=True)

gives:

    metadata = MetaData(engine,reflect=True)
  File "/opt/buildout-eggs/SQLAlchemy-0.6.4-py2.5.egg/sqlalchemy/schema.py", line 1927, in __init__
    self.reflect()
  File "/opt/buildout-eggs/SQLAlchemy-0.6.4-py2.5.egg/sqlalchemy/schema.py", line 2037, in reflect
    connection=conn))
  File "/opt/buildout-eggs/SQLAlchemy-0.6.4-py2.5.egg/sqlalchemy/engine/base.py", line 1852, in table_names
    return self.dialect.get_table_names(conn, schema)
  File "<string>", line 1, in <lambda>
  File "/opt/buildout-eggs/SQLAlchemy-0.6.4-py2.5.egg/sqlalchemy/engine/reflection.py", line 32, in cache
    return fn(self, con, *args, **kw)
  File "/opt/buildout-eggs/SQLAlchemy-0.6.4-py2.5.egg/sqlalchemy/dialects/mysql/base.py", line 1791, in get_table_names
    self.identifier_preparer.quote_identifier(current_schema))
  File "/opt/buildout-eggs/SQLAlchemy-0.6.4-py2.5.egg/sqlalchemy/sql/compiler.py", line 1517, in quote_identifier
    return self.initial_quote + self._escape_identifier(value) + self.final_quote
  File "/opt/buildout-eggs/SQLAlchemy-0.6.4-py2.5.egg/sqlalchemy/dialects/mysql/mysqldb.py", line 77, in _escape_identifier
    value = value.replace(self.escape_quote, self.escape_to_quote)
AttributeError: 'NoneType' object has no attribute 'replace'

The issue appears to be the lack of database name in the url.
However, that seems a legit use case given the new multi-schema support...

Comments (7)

  1. Chris Withers reporter

    tuple(engine.execute('SELECT DATABASE()')) ((None,),)

    That returns what I would expect, since no database is specified in the url. I suppose the naive expectation of reflecting from an engine not connected to a specific database is that all tables in all databases should be reflected.

    If that's not trivial to implement, then perhaps some explicit exception should be raised.

    That said, how would you set things up so that "SELECT DATABASE()" returned something other than None other than by specifying the database in the url?

  2. Michael Bayer repo owner

    Frustrating since we can't really add that exception generically, it would be a MySQL thing.

    Usually database usernames have some kind of "default" schema that comes up when login occurs.

    I'm not opposed to supporting "no database selected" mode but for the foreseeable future I'd rather leave it as an unsupported thing, as I'd like any solution to take into account the full variety of backends.

  3. Log in to comment