Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions airflow/providers/opensearch/hooks/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ def delete(self, index_name: str, query: dict | None = None, doc_id: int | None
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]:
Expand Down
2 changes: 2 additions & 0 deletions contributing-docs/08_static_code_checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
4 changes: 2 additions & 2 deletions dev/breeze/doc/images/output_static-checks.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_static-checks.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a1e2a1891a99d349277636539dc4b9c3
37ca01711f349da3aba13f69eab8cd85
1 change: 1 addition & 0 deletions dev/breeze/src/airflow_breeze/pre_commit_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"mypy-docs",
"mypy-providers",
"pretty-format-json",
"pylint",
"python-no-log-warn",
"replace-bad-characters",
"rst-backticks",
Expand Down
14 changes: 10 additions & 4 deletions tests/providers/opensearch/hooks/test_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import pytest

from airflow.exceptions import AirflowException
from airflow.providers.opensearch.hooks.opensearch import OpenSearchHook

pytestmark = pytest.mark.db_test
Expand All @@ -28,15 +29,20 @@

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"]}}},
)

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")