reflection issue with mysql, url with no schema failure
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)
-
reporter -
reporter try again, is plain text too much to ask for? ;-)
-
reporter win?
-
repo owner "current_schema" is not taken from the URL, its taken from
SELECT DATABASE()
. Is that call working for you ? -
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?
-
repo owner - changed milestone to blue sky
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.
-
repo owner - changed title to reflection issue with mysql, url with no schema failure
- Log in to comment
try and fix formatting