From 0ed81826ffa9cf9cf538e70a0c95832701655ce0 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 1 Sep 2022 17:21:44 -0400 Subject: [PATCH] Fix offline mode for helper function --- lib/galaxy/model/migrations/util.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/model/migrations/util.py b/lib/galaxy/model/migrations/util.py index 5163b2ff1c2..4985770dca9 100644 --- a/lib/galaxy/model/migrations/util.py +++ b/lib/galaxy/model/migrations/util.py @@ -1,6 +1,9 @@ import logging -from alembic import op +from alembic import ( + context, + op, +) from sqlalchemy import inspect log = logging.getLogger(__name__) @@ -12,7 +15,19 @@ def drop_column(table_name, column_name): def column_exists(table_name, column_name): + if is_offline_mode(): + msg = ( + "This script is being executed in offline mode and cannot connect to the database. " + f"Therefore, `column_exists({table_name}, {column_name})` returns `False` by default." + ) + log.debug(msg) + return False bind = op.get_context().bind insp = inspect(bind) columns = insp.get_columns(table_name) return any(c["name"] == column_name for c in columns) + + +def is_offline_mode(): + cmd_opts = context.config.cmd_opts + return cmd_opts and cmd_opts.sql