Skip to content
Merged
10 changes: 10 additions & 0 deletions google/cloud/dataproc_spark_connect/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
PermissionDenied,
)
from google.api_core.future.polling import POLLING_PREDICATE
from google.auth.exceptions import DefaultCredentialsError
from google.cloud.dataproc_spark_connect.client import DataprocChannelBuilder
from google.cloud.dataproc_spark_connect.exceptions import DataprocSparkConnectException
from google.cloud.dataproc_spark_connect.pypi_artifacts import PyPiArtifacts
Expand Down Expand Up @@ -456,6 +457,15 @@ def create_session_pbar():
raise DataprocSparkConnectException(
f"Error while creating Dataproc Session: {e.message}"
)
except DefaultCredentialsError as e:
stop_create_session_pbar_event.set()
if create_session_pbar_thread.is_alive():
create_session_pbar_thread.join()
DataprocSparkSession._active_s8s_session_id = None
DataprocSparkSession._active_session_uses_custom_id = False
raise DataprocSparkConnectException(
f"Error while creating Dataproc Session: {e}"
)
except Exception as e:
stop_create_session_pbar_event.set()
if create_session_pbar_thread.is_alive():
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,15 @@ def test_create_session_without_location(self):
except DataprocSparkConnectException as e:
self.assertIn("location is not set", str(e))

def test_create_session_without_application_default_credentials(self):
"""Tests that an exception is raised when application default credentials is not provided."""
os.environ.clear()
try:
DataprocSparkSession.builder.location("test-region").projectId(
"test-project"
).getOrCreate()
except DataprocSparkConnectException as e:
self.assertIn("Your default credentials were not found", str(e))

class DataprocSparkConnectClientTest(unittest.TestCase):

Expand Down
Loading