From 5d997476f703e0b26335db09de52c48895191a10 Mon Sep 17 00:00:00 2001 From: M Bernt Date: Wed, 8 Jul 2020 10:19:21 +0200 Subject: [PATCH] database_exists: don't connect to 'postgres' data base for database existence check (#372) * database_exists: remove rewriting of database for connection strings starting with 'postgres' the function tested for the database with the name 'postgres' instead of the database specified by the url. This has been introduced here (the if else branch probably made sense in dro and create, but it doesn't here in my opinion) https://github.com/kvesteri/sqlalchemy-utils/commit/5d741c16662cde063e6930e7d3fe87b00ae9b8bb https://github.com/kvesteri/sqlalchemy-utils/commit/d7f2905a39a02a2aa5b7b81640abe8cfd07e8771 * fix --- sqlalchemy_utils/functions/database.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sqlalchemy_utils/functions/database.py b/sqlalchemy_utils/functions/database.py index 392aab03..9613e126 100644 --- a/sqlalchemy_utils/functions/database.py +++ b/sqlalchemy_utils/functions/database.py @@ -458,12 +458,7 @@ def sqlite_file_exists(database): return header[:16] == b'SQLite format 3\x00' url = copy(make_url(url)) - database = url.database - if url.drivername.startswith('postgres'): - url.database = 'postgres' - else: - url.database = None - + database, url.database = url.database, None engine = sa.create_engine(url) if engine.dialect.name == 'postgresql':