Skip to content

Commit

Permalink
Fix TRY002 for apache hive provider (#38781)
Browse files Browse the repository at this point in the history
* Mark general exception as ValueError instead

* incorporate TRY002
  • Loading branch information
amoghrajesh committed Apr 5, 2024
1 parent d2f11f0 commit cec6d31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 9 additions & 5 deletions airflow/providers/apache/hive/hooks/hive.py
Expand Up @@ -199,22 +199,26 @@ def _prepare_cli_cmd(self) -> list[Any]:
def _validate_beeline_parameters(self, conn):
if self.high_availability:
if ";" in conn.schema:
raise Exception(
raise ValueError(
f"The schema used in beeline command ({conn.schema}) should not contain ';' character)"
)
return
elif ":" in conn.host or "/" in conn.host or ";" in conn.host:
raise Exception(
raise ValueError(
f"The host used in beeline command ({conn.host}) should not contain ':/;' characters)"
)
try:
int_port = int(conn.port)
if not 0 < int_port <= 65535:
raise Exception(f"The port used in beeline command ({conn.port}) should be in range 0-65535)")
raise ValueError(
f"The port used in beeline command ({conn.port}) should be in range 0-65535)"
)
except (ValueError, TypeError) as e:
raise Exception(f"The port used in beeline command ({conn.port}) should be a valid integer: {e})")
raise ValueError(
f"The port used in beeline command ({conn.port}) should be a valid integer: {e})"
)
if ";" in conn.schema:
raise Exception(
raise ValueError(
f"The schema used in beeline command ({conn.schema}) should not contain ';' character)"
)

Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Expand Up @@ -395,8 +395,6 @@ combine-as-imports = true
# apache.hdfs
"airflow/providers/apache/hdfs/hooks/hdfs.py" = ["TRY002"]
"airflow/providers/apache/hdfs/sensors/hdfs.py" = ["TRY002"]
# apache.hive
"airflow/providers/apache/hive/hooks/hive.py" = ["TRY002"]
# cncf.kubernetes
"airflow/providers/cncf/kubernetes/operators/pod.py" = ["TRY002"]
# common.sql
Expand Down

0 comments on commit cec6d31

Please sign in to comment.