Using as_sql=True and autogenerate results in exception in SQLAlchemy and alembic #266
Migrated issue, originally created by Johannes Erdfelt (@jerdfelt)
I tested this using the trunk versions of both alembic and SQLAlchemy.
Using a simple test program with as_sql=True, an exception occurs in SQLAlchemy:
It appears that the mock engine used when as_sql is True doesn't return self from the connect() method (and also doesn't have a close() method at all).
If I add simple connect() and close() methods in MockConnection, then I run into another exception:
Looking at the code, it seems like the connection passed in gets discarded in lieu of the mock connection. So it makes me think that the autogenerate code would never work with as_sql=True.
I've worked around this (or maybe this is what I should be doing all along) by creating two different contexts. One with as_sql=False for alembic.autogenerate and then one with as_sql=True for alembic.operations.
The text was updated successfully, but these errors were encountered:
Johannes Erdfelt (@jerdfelt) wrote:
Well, I created one context that I used for autogenerate and then for operations. It seemed like it should work at the time! :)
I certainly can live with creating two contexts as what should be done. If so, would you be against a small patch that raises a clearer exception if as_sql=True is used with autogenerate? I guess an alternative would be to ignore as_sql for autogenerate, but that might be confusing if people expect as_sql to never contact the database.