This is an automated email from the ASF dual-hosted git repository.
uranusjr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new b042042086 Remove unnecessary call to keys() method on dictionaries
(#34260)
b042042086 is described below
commit b0420420864b6ada45260e0d00b1b6e72595a966
Author: Pankaj Koti <[email protected]>
AuthorDate: Thu Sep 14 09:06:23 2023 +0530
Remove unnecessary call to keys() method on dictionaries (#34260)
---
airflow/providers/google/cloud/hooks/bigquery.py | 2 +-
airflow/providers/google/cloud/transfers/gcs_to_bigquery.py | 2 +-
airflow/providers/google/cloud/utils/field_validator.py | 6 ++++--
airflow/ti_deps/deps/trigger_rule_dep.py | 2 +-
airflow/utils/process_utils.py | 2 +-
tests/providers/google/cloud/utils/test_field_validator.py | 4 +++-
6 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/airflow/providers/google/cloud/hooks/bigquery.py
b/airflow/providers/google/cloud/hooks/bigquery.py
index be486c6c8d..19bc0fc6f6 100644
--- a/airflow/providers/google/cloud/hooks/bigquery.py
+++ b/airflow/providers/google/cloud/hooks/bigquery.py
@@ -659,7 +659,7 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
],
"googleSheetsOptions": ["skipLeadingRows"],
}
- if source_format in src_fmt_to_param_mapping.keys():
+ if source_format in src_fmt_to_param_mapping:
valid_configs =
src_fmt_to_configs_mapping[src_fmt_to_param_mapping[source_format]]
src_fmt_configs = _validate_src_fmt_configs(
source_format, src_fmt_configs, valid_configs,
backward_compatibility_configs
diff --git a/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
b/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
index 97b2943fb5..f3ece4fb07 100644
--- a/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
+++ b/airflow/providers/google/cloud/transfers/gcs_to_bigquery.py
@@ -532,7 +532,7 @@ class GCSToBigQueryOperator(BaseOperator):
],
"googleSheetsOptions": ["skipLeadingRows"],
}
- if self.source_format in src_fmt_to_param_mapping.keys():
+ if self.source_format in src_fmt_to_param_mapping:
valid_configs =
src_fmt_to_configs_mapping[src_fmt_to_param_mapping[self.source_format]]
self.src_fmt_configs = self._validate_src_fmt_configs(
self.source_format, self.src_fmt_configs, valid_configs,
backward_compatibility_configs
diff --git a/airflow/providers/google/cloud/utils/field_validator.py
b/airflow/providers/google/cloud/utils/field_validator.py
index 415351c69c..1a3ccbff40 100644
--- a/airflow/providers/google/cloud/utils/field_validator.py
+++ b/airflow/providers/google/cloud/utils/field_validator.py
@@ -258,7 +258,7 @@ class GcpBodyFieldValidator(LoggingMixin):
validation_spec=child_validation_spec,
dictionary_to_validate=value, parent=full_field_path
)
all_dict_keys = {spec["name"] for spec in children_validation_specs}
- for field_name in value.keys():
+ for field_name in value:
if field_name not in all_dict_keys:
self.log.warning(
"The field '%s' is in the body, but is not specified in
the "
@@ -421,6 +421,8 @@ class GcpBodyFieldValidator(LoggingMixin):
:param body_to_validate: body that must follow the specification
:return: None
"""
+ if body_to_validate is None:
+ raise RuntimeError("The body to validate is `None`. Please provide
a dictionary to validate.")
try:
for validation_spec in self._validation_specs:
self._validate_field(validation_spec=validation_spec,
dictionary_to_validate=body_to_validate)
@@ -441,7 +443,7 @@ class GcpBodyFieldValidator(LoggingMixin):
if nested_union_spec.get("type") != "union"
and nested_union_spec.get("api_version") != self._api_version
)
- for field_name in body_to_validate.keys():
+ for field_name in body_to_validate:
if field_name not in all_field_names:
self.log.warning(
"The field '%s' is in the body, but is not specified in
the "
diff --git a/airflow/ti_deps/deps/trigger_rule_dep.py
b/airflow/ti_deps/deps/trigger_rule_dep.py
index 82035a742d..670dcd5bff 100644
--- a/airflow/ti_deps/deps/trigger_rule_dep.py
+++ b/airflow/ti_deps/deps/trigger_rule_dep.py
@@ -194,7 +194,7 @@ class TriggerRuleDep(BaseTIDep):
return
# Otherwise we need to figure out which map indexes are depended on
# for each upstream by the current task instance.
- for upstream_id in relevant_tasks.keys():
+ for upstream_id in relevant_tasks:
map_indexes = _get_relevant_upstream_map_indexes(upstream_id)
if map_indexes is None: # All tis of this upstream are
dependencies.
yield (TaskInstance.task_id == upstream_id)
diff --git a/airflow/utils/process_utils.py b/airflow/utils/process_utils.py
index 1f7c4771e8..6e9bb47d21 100644
--- a/airflow/utils/process_utils.py
+++ b/airflow/utils/process_utils.py
@@ -284,7 +284,7 @@ def patch_environ(new_env_variables: dict[str, str]) ->
Generator[None, None, No
After leaving the context, it restores its original state.
:param new_env_variables: Environment variables to set
"""
- current_env_state = {key: os.environ.get(key) for key in
new_env_variables.keys()}
+ current_env_state = {key: os.environ.get(key) for key in new_env_variables}
os.environ.update(new_env_variables)
try:
yield
diff --git a/tests/providers/google/cloud/utils/test_field_validator.py
b/tests/providers/google/cloud/utils/test_field_validator.py
index 920636e724..e504de795e 100644
--- a/tests/providers/google/cloud/utils/test_field_validator.py
+++ b/tests/providers/google/cloud/utils/test_field_validator.py
@@ -40,7 +40,9 @@ class TestGcpBodyFieldValidator:
validator = GcpBodyFieldValidator(specification, "v1")
- with pytest.raises(AttributeError):
+ with pytest.raises(
+ RuntimeError, match="The body to validate is `None`. Please
provide a dictionary to validate."
+ ):
validator.validate(body)
def test_validate_should_fail_if_specification_is_none(self):