Skip to content

Commit

Permalink
Combine similar if logics in providers (#33987)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-awala committed Sep 3, 2023
1 parent c828066 commit fa5e54c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 21 deletions.
4 changes: 1 addition & 3 deletions airflow/providers/amazon/aws/utils/sqs.py
Expand Up @@ -38,9 +38,7 @@ def process_response(
:param response: The response from SQS
:return: The processed response
"""
if not isinstance(response, dict):
return []
elif "Messages" not in response:
if not isinstance(response, dict) or "Messages" not in response:
return []

messages = response["Messages"]
Expand Down
4 changes: 1 addition & 3 deletions airflow/providers/celery/executors/celery_executor.py
Expand Up @@ -368,9 +368,7 @@ def update_task_state(self, key: TaskInstanceKey, state: str, info: Any) -> None
self.success(key, info)
elif state in (celery_states.FAILURE, celery_states.REVOKED):
self.fail(key, info)
elif state == celery_states.STARTED:
pass
elif state == celery_states.PENDING:
elif state in (celery_states.STARTEDstate, celery_states.PENDING):
pass
else:
self.log.info("Unexpected state for %s: %s", key, state)
Expand Down
8 changes: 2 additions & 6 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Expand Up @@ -1003,14 +1003,10 @@ def __enter__(self):
def __exit__(self, exctype, excinst, exctb):
error = exctype is not None
matching_error = error and issubclass(exctype, self._exceptions)
if error and not matching_error:
return False
elif matching_error and self.reraise:
if (error and not matching_error) or (matching_error and self.reraise):
return False
elif matching_error:
self.exception = excinst
logger = logging.getLogger(__name__)
logger.exception(excinst)
return True
else:
return True
return True
6 changes: 3 additions & 3 deletions airflow/providers/google/cloud/log/gcs_task_handler.py
Expand Up @@ -263,8 +263,8 @@ def no_log_found(exc):
:meta private:
"""
if exc.args and isinstance(exc.args[0], str) and "No such object" in exc.args[0]:
return True
elif getattr(exc, "resp", {}).get("status") == "404":
if (exc.args and isinstance(exc.args[0], str) and "No such object" in exc.args[0]) or getattr(
exc, "resp", {}
).get("status") == "404":
return True
return False
4 changes: 1 addition & 3 deletions airflow/providers/google/cloud/transfers/cassandra_to_gcs.py
Expand Up @@ -258,9 +258,7 @@ def generate_data_dict(self, names: Iterable[str], values: Any) -> dict[str, Any

def convert_value(self, value: Any | None) -> Any | None:
"""Convert value to BQ type."""
if not value:
return value
elif isinstance(value, (str, int, float, bool, dict)):
if not value or isinstance(value, (str, int, float, bool, dict)):
return value
elif isinstance(value, bytes):
return b64encode(value).decode("ascii")
Expand Down
4 changes: 1 addition & 3 deletions airflow/providers/oracle/hooks/oracle.py
Expand Up @@ -295,9 +295,7 @@ def insert_rows(
for cell in row:
if isinstance(cell, str):
lst.append("'" + str(cell).replace("'", "''") + "'")
elif cell is None:
lst.append("NULL")
elif isinstance(cell, float) and math.isnan(cell): # coerce numpy NaN to NULL
elif cell is None or isinstance(cell, float) and math.isnan(cell): # coerce numpy NaN to NULL
lst.append("NULL")
elif numpy and isinstance(cell, numpy.datetime64):
lst.append("'" + str(cell) + "'")
Expand Down

0 comments on commit fa5e54c

Please sign in to comment.