fix(DB update): Gracefully handle querry error during DB update (#33250)

This commit is contained in:
Vitor Avila
2025-04-25 15:38:59 -03:00
committed by GitHub
parent ac636c73ae
commit de84a534ac
3 changed files with 45 additions and 3 deletions

View File

@@ -80,9 +80,19 @@ class UpdateDatabaseCommand(BaseCommand):
# existing personal tokens.
self._handle_oauth2()
# build new DB
# Some DBs require running a query to get the default catalog.
# In these cases, if the current connection is broken then
# `get_default_catalog` would raise an exception. We need to
# gracefully handle that so that the connection can be fixed.
original_database_name = self._model.database_name
original_catalog = self._model.get_default_catalog()
force_update: bool = False
try:
original_catalog = self._model.get_default_catalog()
except Exception:
original_catalog = None
force_update = True
# build new DB
database = DatabaseDAO.update(self._model, self._properties)
database.set_sqlalchemy_uri(database.sqlalchemy_uri)
ssh_tunnel = self._handle_ssh_tunnel(database)
@@ -92,7 +102,8 @@ class UpdateDatabaseCommand(BaseCommand):
# configured with multi-catalog support; if it was enabled or is enabled in the
# update we don't update the assets
if (
new_catalog != original_catalog
force_update
or new_catalog != original_catalog
and not self._model.allow_multi_catalog
and not database.allow_multi_catalog
):