Skip to content
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

Add future=True flag to SA engine #17174

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add future=True flag to SA engine
  • Loading branch information
jdavcs committed Dec 12, 2023
commit 475f7227c4a63da546768d1852f62b682336931f
2 changes: 1 addition & 1 deletion lib/galaxy/model/database_utils.py
Original file line number Diff line number Diff line change
@@ -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:
4 changes: 2 additions & 2 deletions lib/galaxy/model/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion lib/galaxy/model/migrations/alembic/env.py
Original file line number Diff line number Diff line change
@@ -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():
6 changes: 3 additions & 3 deletions lib/galaxy/model/migrations/scripts.py
Original file line number Diff line number Diff line change
@@ -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():
@@ -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)
@@ -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:
2 changes: 1 addition & 1 deletion lib/galaxy/model/orm/engine_factory.py
Original file line number Diff line number Diff line change
@@ -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())
Original file line number Diff line number Diff line change
@@ -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()
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
@@ -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:
@@ -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}")
2 changes: 1 addition & 1 deletion lib/tool_shed/webapp/model/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
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
@@ -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():
2 changes: 1 addition & 1 deletion scripts/check_model.py
Original file line number Diff line number Diff line change
@@ -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)

2 changes: 1 addition & 1 deletion scripts/update_shed_config_path.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion test/unit/data/model/conftest.py
Original file line number Diff line number Diff line change
@@ -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