Skip to content

Commit

Permalink
Add future=True flag to SA engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Dec 12, 2023
1 parent 819a799 commit 475f722
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/model/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_database(db_url, database=None, encoding="utf8", template=None):

@contextmanager
def sqlalchemy_engine(url):
engine = create_engine(url)
engine = create_engine(url, future=True)
try:
yield engine
finally:
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/model/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ def verify_databases_via_script(
) -> None:
# This function serves a use case when an engine has not been created yet
# (e.g. when called from a script).
gxy_engine = create_engine(gxy_config.url)
gxy_engine = create_engine(gxy_config.url, future=True)
tsi_engine = None
if tsi_config.url and tsi_config.url != gxy_config.url:
tsi_engine = create_engine(tsi_config.url)
tsi_engine = create_engine(tsi_config.url, future=True)

verify_databases(
gxy_engine,
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/model/migrations/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _configure_and_run_migrations_offline(url: str) -> None:


def _configure_and_run_migrations_online(url) -> None:
engine = create_engine(url)
engine = create_engine(url, future=True)
with engine.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/model/migrations/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def verify_database_is_initialized(db_url: str) -> None:
if not database_exists(db_url):
raise DatabaseDoesNotExistError(db_url)

engine = create_engine(db_url)
engine = create_engine(db_url, future=True)
try:
db_state = DatabaseStateCache(engine=engine)
if db_state.is_database_empty() or db_state.contains_only_kombu_tables():
Expand Down Expand Up @@ -161,7 +161,7 @@ def get_gxy_db_version(self, gxy_db_url=None):
"""
db_url = gxy_db_url or self.gxy_db_url
try:
engine = create_engine(db_url)
engine = create_engine(db_url, future=True)
version = self._get_gxy_alembic_db_version(engine)
if not version:
version = self._get_gxy_sam_db_version(engine)
Expand Down Expand Up @@ -197,7 +197,7 @@ def _rename_arg(self, argv, old_name, new_name) -> None:

def _upgrade(self, db_url, model):
try:
engine = create_engine(db_url)
engine = create_engine(db_url, future=True)
am = get_alembic_manager(engine)
am.upgrade(model)
finally:
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/model/orm/engine_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def after_cursor_execute(conn, cursor, statement, parameters, context, executema

engine_options = engine_options or {}
engine_options = set_sqlite_connect_args(engine_options, url)
engine = create_engine(url, **engine_options)
engine = create_engine(url, **engine_options, future=True)

# Prevent sharing connection across fork: https://docs.sqlalchemy.org/en/14/core/pooling.html#using-connection-pools-with-multiprocessing-or-os-fork
register_after_fork(engine, lambda e: e.dispose())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def run_command(cmd: str) -> subprocess.CompletedProcess:
def get_db_heads(config: Config) -> Tuple[str, ...]:
"""Return revision ids (version heads) stored in the database."""
dburl = config.get_main_option("sqlalchemy.url")
engine = create_engine(dburl)
engine = create_engine(dburl, future=True)
with engine.connect() as conn:
context = MigrationContext.configure(conn)
heads = context.get_current_heads()
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/model/unittest_utils/model_testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def drop_existing_database(url: DbUrl) -> Iterator[None]:
@contextmanager
def disposing_engine(url: DbUrl) -> Iterator[Engine]:
"""Context manager for engine that disposes of its connection pool on exit."""
engine = create_engine(url)
engine = create_engine(url, future=True)
try:
yield engine
finally:
Expand Down Expand Up @@ -233,7 +233,7 @@ def _drop_postgres_database(url: DbUrl) -> None:


def _drop_database(connection_url, database_name):
engine = create_engine(connection_url, isolation_level="AUTOCOMMIT")
engine = create_engine(connection_url, isolation_level="AUTOCOMMIT", future=True)
preparer = IdentifierPreparer(engine.dialect)
database_name = preparer.quote(database_name)
stmt = text(f"DROP DATABASE IF EXISTS {database_name}")
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/webapp/model/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self) -> None:

def verify_database(url, engine_options=None) -> None:
engine_options = engine_options or {}
engine = create_engine(url, **engine_options)
engine = create_engine(url, **engine_options, future=True)
verifier = DatabaseStateVerifier(engine)
verifier.run()
engine.dispose()
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/webapp/model/migrations/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _configure_and_run_migrations_offline(url: str) -> None:


def _configure_and_run_migrations_online(url) -> None:
engine = create_engine(url)
engine = create_engine(url, future=True)
with engine.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def load_indexes(metadata):
# create EMPTY metadata, then load from database
db_url = get_config(sys.argv)["db_url"]
metadata = MetaData()
engine = create_engine(db_url)
engine = create_engine(db_url, future=True)
metadata.reflect(bind=engine)
indexes_in_db = load_indexes(metadata)

Expand Down
2 changes: 1 addition & 1 deletion scripts/update_shed_config_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_database(config_file):
exit(1)

# Initialize the database connection.
engine = create_engine(database_connection)
engine = create_engine(database_connection, future=True)
MetaData(bind=engine)
install_session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True))
model = mapping.init(database_connection)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/data/model/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def sqlite_memory_url():
@pytest.fixture(scope="module")
def engine():
db_uri = "sqlite:///:memory:"
return create_engine(db_uri)
return create_engine(db_uri, future=True)


@pytest.fixture
Expand Down

0 comments on commit 475f722

Please sign in to comment.