diff --git a/backend/dataall/modules/s3_datasets_shares/services/s3_share_service.py b/backend/dataall/modules/s3_datasets_shares/services/s3_share_service.py index 255544bc7..f77e55445 100644 --- a/backend/dataall/modules/s3_datasets_shares/services/s3_share_service.py +++ b/backend/dataall/modules/s3_datasets_shares/services/s3_share_service.py @@ -9,6 +9,8 @@ from dataall.core.environment.services.environment_service import EnvironmentService from dataall.core.tasks.db.task_models import Task from dataall.core.tasks.service_handlers import Worker +from dataall.modules.datasets_base.db.dataset_models import DatasetBase +from dataall.modules.datasets_base.db.dataset_repositories import DatasetBaseRepository from dataall.modules.shares_base.db.share_object_repositories import ShareObjectRepository from dataall.modules.shares_base.db.share_state_machines_repositories import ShareStatusRepository from dataall.modules.shares_base.services.share_item_service import ShareItemService @@ -255,8 +257,18 @@ def list_shared_databases_tables_with_env_group(environmentUri: str, groupUri: s @staticmethod def resolve_shared_db_name(GlueDatabaseName: str, shareUri: str, targetEnvAwsAccountId: str, targetEnvRegion: str): - old_shared_db_name = (GlueDatabaseName + '_shared_' + shareUri)[:254] - database = GlueClient( - account_id=targetEnvAwsAccountId, database=old_shared_db_name, region=targetEnvRegion - ).get_glue_database() - return old_shared_db_name if database else GlueDatabaseName + '_shared' + with get_context().db_engine.scoped_session() as session: + share = ShareObjectRepository.get_share_by_uri(session, shareUri) + dataset = DatasetBaseRepository.get_dataset_by_uri(session, share.datasetUri) + try: + datasetGlueDatabase = GlueClient( + account_id=dataset.AwsAccountId, region=dataset.region, database=GlueDatabaseName + ).get_glue_database_from_catalog() + except Exception as e: + log.info(f'Error while calling the get_glue_database_from_catalog when resolving db name due to: {e}') + datasetGlueDatabase = GlueDatabaseName + old_shared_db_name = (datasetGlueDatabase + '_shared_' + shareUri)[:254] + database = GlueClient( + account_id=targetEnvAwsAccountId, database=old_shared_db_name, region=targetEnvRegion + ).get_glue_database() + return old_shared_db_name if database else datasetGlueDatabase + '_shared'