You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2024/02/29 20:42:45 UTC
(airflow) branch main updated: Fix "Exception statement has no effect" (#37722)
This is an automated email from the ASF dual-hosted git repository.
potiuk 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 a538e02d01 Fix "Exception statement has no effect" (#37722)
a538e02d01 is described below
commit a538e02d01a0ead0c6f9242067aeffbaf8b67038
Author: Andrey Anshin <An...@taragol.is>
AuthorDate: Fri Mar 1 00:42:38 2024 +0400
Fix "Exception statement has no effect" (#37722)
* Fix "Exception statement has no effect"
* Add link to the ruff issue tracker
* update breeze hashes
---
.pre-commit-config.yaml | 18 ++++++++++++++++++
airflow/providers/opensearch/hooks/opensearch.py | 5 +++--
contributing-docs/08_static_code_checks.rst | 2 ++
dev/breeze/doc/images/output_static-checks.svg | 4 ++--
dev/breeze/doc/images/output_static-checks.txt | 2 +-
dev/breeze/src/airflow_breeze/pre_commit_ids.py | 1 +
tests/providers/opensearch/hooks/test_opensearch.py | 14 ++++++++++----
7 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a4590e2312..7f5fca84ae 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1107,6 +1107,24 @@ repos:
- "B301,B324,B403,B404,B603"
- "--severity-level"
- "high" # TODO: remove this line when we fix all the issues
+ - id: pylint
+ name: pylint
+ description: "Pylint is a static code analyser for Python 2 or 3."
+ entry: pylint
+ language: python
+ language_version: python3
+ types: [ python ]
+ additional_dependencies: ['pylint==3.1.0']
+ require_serial: true
+ files: ^airflow/.*
+ exclude:
+ airflow/example_dags/.*
+ args:
+ # Use pylint only for the specific check, which are not available into the ruff
+ - "--disable=all"
+ # W0133: "Exception statement has no effect"
+ # see: https://github.com/astral-sh/ruff/issues/10145
+ - "--enable=W0133"
- id: check-fab-migrations
language: pygrep
name: Check no migration is done on FAB related table
diff --git a/airflow/providers/opensearch/hooks/opensearch.py b/airflow/providers/opensearch/hooks/opensearch.py
index 793741d150..2b4c254b4a 100644
--- a/airflow/providers/opensearch/hooks/opensearch.py
+++ b/airflow/providers/opensearch/hooks/opensearch.py
@@ -102,8 +102,9 @@ class OpenSearchHook(BaseHook):
return self.client.delete_by_query(index=index_name, body=query)
elif doc_id is not None:
return self.client.delete(index=index_name, id=doc_id)
- else:
- AirflowException("To delete a document you must include one of either a query or a document id. ")
+ raise AirflowException(
+ "To delete a document you must include one of either a query or a document id."
+ )
@classmethod
def get_ui_field_behaviour(cls) -> dict[str, Any]:
diff --git a/contributing-docs/08_static_code_checks.rst b/contributing-docs/08_static_code_checks.rst
index e2fb6e803c..2f6b067d56 100644
--- a/contributing-docs/08_static_code_checks.rst
+++ b/contributing-docs/08_static_code_checks.rst
@@ -307,6 +307,8 @@ require Breeze Docker image to be built locally.
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
| pretty-format-json | Format JSON files | |
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
+| pylint | pylint | |
++-----------------------------------------------------------+--------------------------------------------------------------+---------+
| python-no-log-warn | Check if there are no deprecate log warn | |
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
| replace-bad-characters | Replace bad characters | |
diff --git a/dev/breeze/doc/images/output_static-checks.svg b/dev/breeze/doc/images/output_static-checks.svg
index 722e2a34e4..b92edf65ff 100644
--- a/dev/breeze/doc/images/output_static-checks.svg
+++ b/dev/breeze/doc/images/output_static-checks.svg
@@ -347,8 +347,8 @@
</text><text class="breeze-static-checks-r5" x="0" y="947.2" textLength="12.2" clip-path="url(#breeze-static-checks-line-38)">│</text><text class="breeze-static-checks-r7" x="451.4" y="947.2" textLength="988.2" clip-path="url(#breeze-static-checks-line-38)">lint-chart-schema | lint-css | lint-dockerfile | lint-helm-chart |               </text><text class="breeze-static-checks-r5 [...]
</text><text class="breeze-static-checks-r5" x="0" y="971.6" textLength="12.2" clip-path="url(#breeze-static-checks-line-39)">│</text><text class="breeze-static-checks-r7" x="451.4" y="971.6" textLength="988.2" clip-path="url(#breeze-static-checks-line-39)">lint-json-schema | lint-markdown | lint-openapi | mixed-line-ending |            </text><text class="breeze-static-checks-r5" x="1451.8" y= [...]
</text><text class="breeze-static-checks-r5" x="0" y="996" textLength="12.2" clip-path="url(#breeze-static-checks-line-40)">│</text><text class="breeze-static-checks-r7" x="451.4" y="996" textLength="988.2" clip-path="url(#breeze-static-checks-line-40)">mypy-airflow | mypy-dev | mypy-docs | mypy-providers | pretty-format-json |      </text><text class="breeze-static-checks-r5" x="1451.8" y="996" textLength="12.2" [...]
-</text><text class="breeze-static-checks-r5" x="0" y="1020.4" textLength="12.2" clip-path="url(#breeze-static-checks-line-41)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1020.4" textLength="988.2" clip-path="url(#breeze-static-checks-line-41)">python-no-log-warn | replace-bad-characters | rst-backticks | ruff | ruff-format </text><text class="breeze-static-checks-r5" x="1451.8" y="1020.4" textLength="12.2" clip-path="url(#breez [...]
-</text><text class="breeze-static-checks-r5" x="0" y="1044.8" textLength="12.2" clip-path="url(#breeze-static-checks-line-42)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1044.8" textLength="988.2" clip-path="url(#breeze-static-checks-line-42)">| shellcheck | trailing-whitespace | ts-compile-format-lint-www |                </text><text class="breeze-static-checks- [...]
+</text><text class="breeze-static-checks-r5" x="0" y="1020.4" textLength="12.2" clip-path="url(#breeze-static-checks-line-41)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1020.4" textLength="988.2" clip-path="url(#breeze-static-checks-line-41)">pylint | python-no-log-warn | replace-bad-characters | rst-backticks | ruff |    </text><text class="breeze-static-checks-r5" x="1451.8" y="1020.4" textLength="12.2" c [...]
+</text><text class="breeze-static-checks-r5" x="0" y="1044.8" textLength="12.2" clip-path="url(#breeze-static-checks-line-42)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1044.8" textLength="988.2" clip-path="url(#breeze-static-checks-line-42)">ruff-format | shellcheck | trailing-whitespace | ts-compile-format-lint-www |    </text><text class="breeze-static-checks-r5" x="1451.8" y="1044.8" textLength="12.2" clip-path=" [...]
</text><text class="breeze-static-checks-r5" x="0" y="1069.2" textLength="12.2" clip-path="url(#breeze-static-checks-line-43)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1069.2" textLength="988.2" clip-path="url(#breeze-static-checks-line-43)">update-black-version | update-breeze-cmd-output |                             [...]
</text><text class="breeze-static-checks-r5" x="0" y="1093.6" textLength="12.2" clip-path="url(#breeze-static-checks-line-44)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1093.6" textLength="988.2" clip-path="url(#breeze-static-checks-line-44)">update-breeze-readme-config-hash | update-build-dependencies |                   </text><text class="breeze-static-checks- [...]
</text><text class="breeze-static-checks-r5" x="0" y="1118" textLength="12.2" clip-path="url(#breeze-static-checks-line-45)">│</text><text class="breeze-static-checks-r7" x="451.4" y="1118" textLength="988.2" clip-path="url(#breeze-static-checks-line-45)">update-chart-dependencies | update-common-sql-api-stubs | update-er-diagram |    </text><text class="breeze-static-checks-r5" x="1451.8" y="1118" textLength="12.2" clip-path="url(#breeze-stat [...]
diff --git a/dev/breeze/doc/images/output_static-checks.txt b/dev/breeze/doc/images/output_static-checks.txt
index d2ec7d8f73..d8f2721576 100644
--- a/dev/breeze/doc/images/output_static-checks.txt
+++ b/dev/breeze/doc/images/output_static-checks.txt
@@ -1 +1 @@
-a1e2a1891a99d349277636539dc4b9c3
+37ca01711f349da3aba13f69eab8cd85
diff --git a/dev/breeze/src/airflow_breeze/pre_commit_ids.py b/dev/breeze/src/airflow_breeze/pre_commit_ids.py
index f2cd05dd93..99a967d463 100644
--- a/dev/breeze/src/airflow_breeze/pre_commit_ids.py
+++ b/dev/breeze/src/airflow_breeze/pre_commit_ids.py
@@ -108,6 +108,7 @@ PRE_COMMIT_LIST = [
"mypy-docs",
"mypy-providers",
"pretty-format-json",
+ "pylint",
"python-no-log-warn",
"replace-bad-characters",
"rst-backticks",
diff --git a/tests/providers/opensearch/hooks/test_opensearch.py b/tests/providers/opensearch/hooks/test_opensearch.py
index 570354dcdf..92f57d276e 100644
--- a/tests/providers/opensearch/hooks/test_opensearch.py
+++ b/tests/providers/opensearch/hooks/test_opensearch.py
@@ -18,6 +18,7 @@ from __future__ import annotations
import pytest
+from airflow.exceptions import AirflowException
from airflow.providers.opensearch.hooks.opensearch import OpenSearchHook
pytestmark = pytest.mark.db_test
@@ -28,8 +29,8 @@ MOCK_SEARCH_RETURN = {"status": "test"}
class TestOpenSearchHook:
def test_hook_search(self, mock_hook):
- self.hook = OpenSearchHook(open_search_conn_id="opensearch_default", log_query=True)
- result = self.hook.search(
+ hook = OpenSearchHook(open_search_conn_id="opensearch_default", log_query=True)
+ result = hook.search(
index_name="testIndex",
query={"size": 1, "query": {"multi_match": {"query": "test", "fields": ["testField"]}}},
)
@@ -37,6 +38,11 @@ class TestOpenSearchHook:
assert result == MOCK_SEARCH_RETURN
def test_hook_index(self, mock_hook):
- self.hook = OpenSearchHook(open_search_conn_id="opensearch_default", log_query=True)
- result = self.hook.index(index_name="test_index", document={"title": "Monty Python"}, doc_id=3)
+ hook = OpenSearchHook(open_search_conn_id="opensearch_default", log_query=True)
+ result = hook.index(index_name="test_index", document={"title": "Monty Python"}, doc_id=3)
assert result == 3
+
+ def test_delete_check_parameters(self):
+ hook = OpenSearchHook(open_search_conn_id="opensearch_default", log_query=True)
+ with pytest.raises(AirflowException, match="must include one of either a query or a document id"):
+ hook.delete(index_name="test_index")