File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
google/cloud/dataproc_spark_connect Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 3939 PermissionDenied ,
4040)
4141from google .api_core .future .polling import POLLING_PREDICATE
42+ from google .auth .exceptions import DefaultCredentialsError
4243from google .cloud .dataproc_spark_connect .client import DataprocChannelBuilder
4344from google .cloud .dataproc_spark_connect .exceptions import DataprocSparkConnectException
4445from google .cloud .dataproc_spark_connect .pypi_artifacts import PyPiArtifacts
@@ -456,6 +457,15 @@ def create_session_pbar():
456457 raise DataprocSparkConnectException (
457458 f"Error while creating Dataproc Session: { e .message } "
458459 )
460+ except DefaultCredentialsError as e :
461+ stop_create_session_pbar_event .set ()
462+ if create_session_pbar_thread .is_alive ():
463+ create_session_pbar_thread .join ()
464+ DataprocSparkSession ._active_s8s_session_id = None
465+ DataprocSparkSession ._active_session_uses_custom_id = False
466+ raise DataprocSparkConnectException (
467+ f"Error while creating Dataproc Session: { e } "
468+ )
459469 except Exception as e :
460470 stop_create_session_pbar_event .set ()
461471 if create_session_pbar_thread .is_alive ():
Original file line number Diff line number Diff line change @@ -1487,6 +1487,16 @@ def test_create_session_without_location(self):
14871487 except DataprocSparkConnectException as e :
14881488 self .assertIn ("location is not set" , str (e ))
14891489
1490+ def test_create_session_without_application_default_credentials (self ):
1491+ """Tests that an exception is raised when application default credentials is not provided."""
1492+ os .environ .clear ()
1493+ try :
1494+ DataprocSparkSession .builder .location ("test-region" ).projectId (
1495+ "test-project"
1496+ ).getOrCreate ()
1497+ except DataprocSparkConnectException as e :
1498+ self .assertIn ("Your default credentials were not found" , str (e ))
1499+
14901500
14911501class DataprocSparkConnectClientTest (unittest .TestCase ):
14921502
You can’t perform that action at this time.
0 commit comments