-
Notifications
You must be signed in to change notification settings - Fork 317
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
Incompatibility of create_database() from sqlalchemy-utils 0.39.0 with SQLAlchemy 2.0.0 #676
Comments
introvenk
added a commit
to introvenk/sqlalchemy-utils
that referenced
this issue
Jan 29, 2023
With SQLAlchemy 2.0 and postgres, 'create_database()'' function from sqlalchemy-utils was failing and the issue was caused by the failure of the quote() function to determine the dialect of the database driver. This was due to the removal of the direct engine.execute() calls in SQLAlchemy 2.0 which caused the get_bind() function to fail in case of Engine object. This change adds a check in the quote() function to see if the input is an engine object. If it is, the dialect attribute is used directly instead of trying to use the get_bind() function. This resolves the issue with create_database() where the get_bind() function was not able to return a bind for the engine object and the subsequent failure of the quote() function. This change allows the 'create_database()'' function from the sqlalchemy-utils library to be compatible with SQLAlchemy 2.0.0 Fixes kvesteri#676
shuva10v
added a commit
to re-doubt/ton-indexer
that referenced
this issue
Jan 29, 2023
Fixed in #690 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Package / Application versions:
Python version: 3.9.0
sqlalchemy: 2.0.0
sqlalchemy-utils: 0.39.0
postgres 14
Description
In SQLAlchemy 2.0, Direct
engine.execute()
calls are no longer supported. The "connectionless" execution pattern, whereengine.execute()
implicitly procures aConnection
object and runs theexecute
method, has several issues and was not intended for frequent use.Due to this change that require the use of
Connection
objects instead ofEngine
objects, thecreate_database()
function from thesqlalchemy-utils
library has become incompatible with SQLAlchemy 2.0The failure is caused by the
get_bind()
function not returning a bind for theEngine
object and the subsequent failure of thequote()
function to determine the dialect and ultimately leading to the failure of thecreate_database()
function. A check in thequote()
function to see if the input is anEngine
object and using thedialect
attribute directly will resolve this issue.Steps to Reproduce
create_database()
function fromsqlalchemy-utils
on an SQLAlchemy 2.0Engine
object.quote()
function due to the failure ofget_bind()
to return a bind for theEngine
object.Expected Result
The
create_database()
function should successfully execute the create database statement.Actual Result
When using the
create_database()
function from thesqlalchemy-utils
library, the underlyingquote()
function thatcreate_database()
depends upon fails and raises an error because it cannot determine the dialect from theEngine
object provided to it, this is because theget_bind()
function expects theEngine
object to have theexecute
attribute but in SQLAlchemy 2.0 it has been changed. The error message reads as follows:TypeError: This method accepts only Session, Engine, Connection and declarative model objects.
Solution
To resolve this issue, a check can be added in the
quote()
function to see if the input is anEngine
object and using thedialect
attribute on it directly. I am raising a pull request with these changes and would welcome any guidance or suggestions to address the underlying issues with the functions.The text was updated successfully, but these errors were encountered: