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
6 changes: 5 additions & 1 deletion airflow/providers/microsoft/azure/operators/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Any, Sequence

from azure.batch import models as batch_models
Expand Down Expand Up @@ -176,7 +177,10 @@ def __init__(
self.timeout = timeout
self.should_delete_job = should_delete_job
self.should_delete_pool = should_delete_pool
self.hook = self.get_hook()

@cached_property
def hook(self):
return self.get_hook()

def _check_inputs(self) -> Any:
if not self.os_family and not self.vm_publisher:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def setup_method(self, method, mock_batch, mock_hook):
self.batch_client = mock_batch.return_value
self.mock_instance = mock_hook.return_value
assert self.batch_client == self.operator.hook.connection
assert self.batch_client == self.operator2_pass.hook.connection
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why, but without that assertion in setup. the test TestAzureBatchOperator::test_execute_without_failures_2 fails with

self = <azure.batch.batch_auth.SharedKeyAuth object at 0xffffafb7fc10>, string_to_sign = 'POST\n\n\n425\n\napplication/json; odata=minimalmetadata; charset=utf-8\n\n\n\n\n\n\nocp-date:Fri, 25 Aug 2023 13:55:20 GMT\n/None/pools\napi-version:2023-05-01.17.0'

    def _sign_string(self, string_to_sign):

>       _key = self._key.encode('utf-8')
E       AttributeError: 'NoneType' object has no attribute 'encode'

Maybe someone can explain it :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it refers to mocking, previously it was instantiate immediately, but now you need to call it (cached).
I've plan also check entire provider for found the same instantiate connection in hook/operators/sensors


@mock.patch.object(AzureBatchHook, "wait_for_all_node_state")
def test_execute_without_failures(self, wait_mock):
Expand Down