You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that flask-sqlalchmy is injecting (the wrong) directory when run, it puts the file directory in instead of the current working directory, causing me to not get a valid database. This means, by the way, that assert file.exists() passes but then a nonexistent file is still opened. I finally figured that out, but in doing so, I decided I wanted to use a URI, as described here: https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#uri-connections - and the injection system completely ruins URI's, by adding a path before the file:.
Which does create and open a file with that name (file:db.sqlite3?mode=ro&uri=true). If it had been absolute, then it would have both paths (/absolute/file/path/to/source/folder/file:/absolute/file/path/to/binary/folder/db.sqlite3?mode=ro&uri=true), which at least won't open because it's a non-existent folder.
This should either only act after the the file: prefix when making this absolute, or just leave it alone when it's a file: and not make it absolute, leaving that to the user. Given that SLQLite happy opens files that don't exist, it is really irritating to mess with this path IMO, but maybe there's a good reason (which is why I don't know which of the two options is the right one to take).
This code is in apply_driver_hacks.
Environment:
Python version: 3.10
Flask-SQLAlchemy version: 2.5.1
SQLAlchemy version: 1.4.32
The text was updated successfully, but these errors were encountered:
I didn't realize file: was a thing. Makes sense to detect that as well and modify it.
Because the current working directory is not always obvious during deployment, Flask-SQLAlchemy makes relative SQLite paths relative to the project root (will change to the instance folder in 3.x). This way, the database ends up in a consistent place, either absolute to begin with or always relative to the project.
I noticed that flask-sqlalchmy is injecting (the wrong) directory when run, it puts the file directory in instead of the current working directory, causing me to not get a valid database. This means, by the way, that
assert file.exists()
passes but then a nonexistent file is still opened. I finally figured that out, but in doing so, I decided I wanted to use a URI, as described here: https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#uri-connections - and the injection system completely ruins URI's, by adding a path before thefile:
.produces
Which does create and open a file with that name (
file:db.sqlite3?mode=ro&uri=true
). If it had been absolute, then it would have both paths (/absolute/file/path/to/source/folder/file:/absolute/file/path/to/binary/folder/db.sqlite3?mode=ro&uri=true
), which at least won't open because it's a non-existent folder.This should either only act after the the
file:
prefix when making this absolute, or just leave it alone when it's afile:
and not make it absolute, leaving that to the user. Given that SLQLite happy opens files that don't exist, it is really irritating to mess with this path IMO, but maybe there's a good reason (which is why I don't know which of the two options is the right one to take).This code is in
apply_driver_hacks
.Environment:
The text was updated successfully, but these errors were encountered: