From bca2366d5a66e0da8bd039c061f8127b67833beb Mon Sep 17 00:00:00 2001 From: Geido <60598000+geido@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:40:28 +0300 Subject: [PATCH] fix(Database): Refresh catalogs on db update returns database error (#29681) (cherry picked from commit 134ca38b8d94c909991df6a74c7bb790205355e1) --- superset/commands/database/update.py | 49 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/superset/commands/database/update.py b/superset/commands/database/update.py index 28f895b2f632b..75aebf322be9d 100644 --- a/superset/commands/database/update.py +++ b/superset/commands/database/update.py @@ -166,36 +166,43 @@ def _refresh_catalogs( ) for catalog in catalogs: - schemas = self._get_schema_names(database, catalog, ssh_tunnel) + try: + schemas = self._get_schema_names(database, catalog, ssh_tunnel) - if catalog: - perm = security_manager.get_catalog_perm( - original_database_name, - catalog, - ) - existing_pvm = security_manager.find_permission_view_menu( - "catalog_access", - perm, - ) - if not existing_pvm: - # new catalog - security_manager.add_permission_view_menu( + if catalog: + perm = security_manager.get_catalog_perm( + original_database_name, + catalog, + ) + existing_pvm = security_manager.find_permission_view_menu( "catalog_access", - security_manager.get_catalog_perm( - database.database_name, - catalog, - ), + perm, ) - for schema in schemas: + if not existing_pvm: + # new catalog security_manager.add_permission_view_menu( - "schema_access", - security_manager.get_schema_perm( + "catalog_access", + security_manager.get_catalog_perm( database.database_name, catalog, - schema, ), ) + for schema in schemas: + security_manager.add_permission_view_menu( + "schema_access", + security_manager.get_schema_perm( + database.database_name, + catalog, + schema, + ), + ) + continue + except DatabaseConnectionFailedError: + # more than one catalog, move to next + if catalog: + logger.warning("Error processing catalog %s", catalog) continue + raise # add possible new schemas in catalog self._refresh_schemas(