Skip to content

Commit 7b7ccc7

Browse files
authored
957 Check for table (#960)
* Remove the trailing \ * Add debuggin * fix when table does not exist * fix linting * Update to 4.0.3 * add details to function
1 parent cf957ee commit 7b7ccc7

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 4.0.2
2+
current_version = 4.0.3
33
commit = False
44
tag = False
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(rc(?P<build>\d+))?

orchestrator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
"""This is the orchestrator workflow engine."""
1515

16-
__version__ = "4.0.2"
16+
__version__ = "4.0.3"
1717

1818
from orchestrator.app import OrchestratorCore
1919
from orchestrator.settings import app_settings

orchestrator/migrations/helpers.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@
2727
def has_table_column(table_name: str, column_name: str, conn: sa.engine.Connection) -> bool:
2828
"""Checks if the specified column exists in a given table.
2929
30+
inspector.get_columns raises an exception if the table does not exist, so we catch that exception and return False.
31+
This is useful for migrations where you want to ensure that a column exists before performing operations on it.
32+
3033
:param table_name: Name of the database table
3134
:param column_name: Name of the column to check
3235
:param conn: SQLAlchemy database Connection
33-
:return: True if column exists, False otherwise
36+
:return: True if the column exists, False otherwise
3437
"""
3538
inspector = sa.inspect(conn.engine)
36-
columns = inspector.get_columns(table_name)
37-
return any(col["name"] == column_name for col in columns)
39+
try:
40+
columns = inspector.get_columns(table_name)
41+
return any(col["name"] == column_name for col in columns)
42+
except sa.exc.NoSuchTableError:
43+
# On some migrations the table might not exist yet, so we catch the exception
44+
logger.warning(f"Table {table_name} does not exist.")
45+
return False
3846

3947

4048
def get_resource_type_id_by_name(conn: sa.engine.Connection, name: str) -> UUID:

0 commit comments

Comments
 (0)