New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ODBC Driver 17 for SQL Server doesn't work with multidb #328
Comments
This is a SQLAlchemy issue, unfortunately I am not related with that project, and I don't have access to a SQL Server database to try this. |
OK, understood. Thanks! |
I was able to solve this by workaround. I didn't dig much into it and but this looks to me like Flask-Migrate or Alembic issue because I don't have any issues with SQLAlchemy or Flask itself with this connection string. I edited
Also SqlServer Connection string can't contain @miguelgrinberg what you think? |
I cannot replicate any SQLAlchemy or Alembic issue with this. the URL passed to create_engine() as well as used within env.py directly has no issue. it appears that SQLALCHEMY_DATABASE_URI may be being passed through various channels including "click" in order for it to be received by Alembic? is it passed as an environment variable to the alembic commandline ? are there points where escaping of some kind may be getting involved ? |
Hi Mike. The env.py that I'm currently using fishes out the database connection URL from the engine object stored in Flask-SQLAlchemy's config.set_main_option(
'sqlalchemy.url',
str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) Before this version was introduced, I obtained the URL directly from Flask's config object: config.set_main_option(
'sqlalchemy.url', current_app.config.get(
'SQLALCHEMY_DATABASE_URI').replace('%', '%%')) So as you see there are no additional layers that could mangle the URL. But I should note that the issue with the |
@zzzeek actually, I believe I may have hinted at the problem. The So really the problem is that I need to pass an exact database URL to Alembic that is accepted as is, and ConfigParser complicates this. I'll see if I can figure out a way to bypass the percent encoding validation. EDIT: after reading the docs on ConfigParser, I'm not sure, it would appear as if percent-encoded characters would also need the |
ConfigParser in Python needs percent signs that are passed as-is to be escaped because it uses percent-sign interpolation: https://docs.python.org/3/library/configparser.html#interpolation-of-values if someone has a percent sign in their password, they need to URL encode that before creating a SQLAlchemy URL, this is described at: https://docs.sqlalchemy.org/en/13/core/engines.html#database-urls so from my end, if someone has a programmatic URL in their program that flask-migrate is going to pass to the Alembic config, it should double the percent signs as this user is doing for their workaround, and that should be it. I'm not fully understanding what flask-migrate is trying to do with passwords. |
also #59 looks like exactly this issue, I'm not looking at any current code right now so I dont understand why there's still a problem. |
@zzzeek that fix went in about a year ago, so yeah I agree, it would appear this should have been handled unless the user was running a very old Flask-Migrate. |
OK but the "fix" impacts a generated env.py that isn't upgraded when users upgrade, so they have to edit the file manually right? that would be the full explanation here. |
It looks like you are discussing the issue not with the OP, but with @tomas223, which has not provided any background information to me. The OP stated that they were running the |
agree, there's several ppl commenting on my issue and this one so for the moment I'm leaning towards a stale env.py as the problem with the user I have on sqlalchemy/sqlalchemy#5332. I think we are done for now. |
I believe the problem was that I downgraded Flask-migrate to match a system where I did not have this problem and my env.py was not overwritten after downgrade. I am able to perform migrations successfully using:
but get the error described in sqlalchemy/sqlalchemy#5332 when using:
Which also causes the multiple calls to DefaultEngineStrategy.create described in that issue.
|
@clabornd can I ask you to add the following prints in your env.py right above the config line?
Then run any flask-migrate command and check these two prints in the output. I'd like to know how these two connection URLs differ. Thanks. |
Not sure if its useful, but: |
Joining in because I have the same problem. My print statements yield the same as @clabornd, and the temporary solution by @tomas223, also worked as expected. I would like to point out that this error does not occur when running the app normally, as it is able to connect to my db (although it has not been updated with flask upgrade), as seen in the stack trace below as table "user" doesn't exist. Hope this is useful in any way. Flask-Migrate==2.5.3 (...) |
@zzzeek so the problem is related to how SQLAlchemy converts its For example, the URL
But a reconstructed URL loses the percent encoding, which is not only an inconvenience but on some URLs like this one also wrong:
Flask-Migrate obtains the database URL from the engine instead of the Flask config because Flask-SQLAlchemy sometimes modifies the URL before passing it down to SQLAlchemy (they call it Do you think this is something that can be fixed in |
sure please post an issue at github.com/sqlalchemy/sqlalchemy and include an MCVE and we'll see if someone can work on that (or provide a PR with tests, after posting the issue) - thanks! |
I'm trying to change my project from a single database to multiple databases. I'm still building it, so it doesn't matter if I lose all of my data. But every time I do a flask db init --multidb and then try to run a flask db migrate, I get the below error:
sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Neither DSN nor SERVER keyword supplied (0) (SQLDriverConnect)')
If I run the init again without the multidb tag, everything works.
Looking at the below item, it seems like it might be an SSL issue, but I'm not sure how to use any of the solutions, since I'm on a Windows computer.
mkleehammer/pyodbc#610
The text was updated successfully, but these errors were encountered: