Skip to content

Commit 05ccfd4

Browse files
authored
Dataproc: Remove default value of region (#23350)
* `region` parameter has no default value. affected functions/classes: `DataprocHook.cancel_job` `DataprocCreateClusterOperator` `DataprocJobBaseOperator` * `DataprocJobBaseOperator`: order of parameters has changed
1 parent c1528f7 commit 05ccfd4

File tree

4 files changed

+11
-35
lines changed

4 files changed

+11
-35
lines changed

airflow/providers/google/CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ Breaking changes
3434
For more information, see `Deprecation and sunset <https://developers.google.com/google-ads/api/docs/sunset-dates>`_
3535
and `Upgrading to the newest version <https://developers.google.com/google-ads/api/docs/version-migration>`_
3636

37+
* ``DataprocJobBaseOperator``: order of parameters has changed
38+
39+
* ``region`` parameter has no default value
40+
affected functions/classes:
41+
``DataprocHook.cancel_job``
42+
``DataprocCreateClusterOperator``
43+
``DataprocJobBaseOperator``
44+
3745
* ``DatastoreHook``: Remove ``datastore_conn_id``. Please use ``gcp_conn_id``
3846

3947
* ``CloudBuildCreateBuildOperator``: Remove ``body``. Please use ``build``

airflow/providers/google/cloud/hooks/dataproc.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,13 +810,6 @@ def cancel_job(
810810
``retry`` is specified, the timeout applies to each individual attempt.
811811
:param metadata: Additional metadata that is provided to the method.
812812
"""
813-
if region is None:
814-
warnings.warn(
815-
"Default region value `global` will be deprecated. Please, provide region value.",
816-
DeprecationWarning,
817-
stacklevel=2,
818-
)
819-
region = 'global'
820813
client = self.get_job_client(region=region)
821814

822815
job = client.cancel_job(

airflow/providers/google/cloud/operators/dataproc.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def __init__(
456456
self,
457457
*,
458458
cluster_name: str,
459-
region: Optional[str] = None,
459+
region: str,
460460
project_id: Optional[str] = None,
461461
cluster_config: Optional[Union[Dict, Cluster]] = None,
462462
virtual_cluster_config: Optional[Dict] = None,
@@ -471,13 +471,6 @@ def __init__(
471471
impersonation_chain: Optional[Union[str, Sequence[str]]] = None,
472472
**kwargs,
473473
) -> None:
474-
if region is None:
475-
warnings.warn(
476-
"Default region value `global` will be deprecated. Please, provide region value.",
477-
DeprecationWarning,
478-
stacklevel=2,
479-
)
480-
region = 'global'
481474

482475
# TODO: remove one day
483476
if cluster_config is None and virtual_cluster_config is None:
@@ -839,6 +832,7 @@ class DataprocJobBaseOperator(BaseOperator):
839832
"""
840833
The base class for operators that launch job on DataProc.
841834
835+
:param region: The specified region where the dataproc cluster is created.
842836
:param job_name: The job name used in the DataProc cluster. This name by default
843837
is the task_id appended with the execution data, but can be templated. The
844838
name will always be appended with a random number to avoid name clashes.
@@ -856,7 +850,6 @@ class DataprocJobBaseOperator(BaseOperator):
856850
:param labels: The labels to associate with this job. Label keys must contain 1 to 63 characters,
857851
and must conform to RFC 1035. Label values may be empty, but, if present, must contain 1 to 63
858852
characters, and must conform to RFC 1035. No more than 32 labels can be associated with a job.
859-
:param region: The specified region where the dataproc cluster is created.
860853
:param job_error_states: Job states that should be considered error states.
861854
Any states in this set will result in an error being raised and failure of the
862855
task. Eg, if the ``CANCELLED`` state should also be considered a task failure,
@@ -889,6 +882,7 @@ class DataprocJobBaseOperator(BaseOperator):
889882
def __init__(
890883
self,
891884
*,
885+
region: str,
892886
job_name: str = '{{task.task_id}}_{{ds_nodash}}',
893887
cluster_name: str = "cluster-1",
894888
project_id: Optional[str] = None,
@@ -897,7 +891,6 @@ def __init__(
897891
gcp_conn_id: str = 'google_cloud_default',
898892
delegate_to: Optional[str] = None,
899893
labels: Optional[Dict] = None,
900-
region: Optional[str] = None,
901894
job_error_states: Optional[Set[str]] = None,
902895
impersonation_chain: Optional[Union[str, Sequence[str]]] = None,
903896
asynchronous: bool = False,
@@ -911,14 +904,6 @@ def __init__(
911904
self.cluster_name = cluster_name
912905
self.dataproc_properties = dataproc_properties
913906
self.dataproc_jars = dataproc_jars
914-
915-
if region is None:
916-
warnings.warn(
917-
"Default region value `global` will be deprecated. Please, provide region value.",
918-
DeprecationWarning,
919-
stacklevel=2,
920-
)
921-
region = 'global'
922907
self.region = region
923908

924909
self.job_error_states = job_error_states if job_error_states is not None else {'ERROR'}

tests/providers/google/cloud/operators/test_dataproc.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,6 @@ def test_deprecation_warning(self):
414414
assert op.cluster_config['worker_config']['num_instances'] == 2
415415
assert "zones/zone" in op.cluster_config['master_config']["machine_type_uri"]
416416

417-
with pytest.warns(DeprecationWarning) as warnings:
418-
op_default_region = DataprocCreateClusterOperator(
419-
task_id=TASK_ID,
420-
project_id=GCP_PROJECT,
421-
cluster_name="cluster_name",
422-
cluster_config=op.cluster_config,
423-
)
424-
assert_warning("Default region value", warnings)
425-
assert op_default_region.region == 'global'
426-
427417
@mock.patch(DATAPROC_PATH.format("Cluster.to_dict"))
428418
@mock.patch(DATAPROC_PATH.format("DataprocHook"))
429419
def test_execute(self, mock_hook, to_dict_mock):

0 commit comments

Comments
 (0)