Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Azure Batch Hook instantation #33731

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Aug 25, 2023

The Hook instantiation for Azure Batch has been done in the constructor, which is wrong. This has been detected when #33716 added example dag and it started to fail provider imports as connection has beeen missing to instantiate it.

The hook instantiation is now moved to cached property.


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

The Hook instantiation for Azure Batch has been done in the
constructor, which is wrong. This has been detected when apache#33716 added
example dag and it started to fail provider imports as connection
has beeen missing to instantiate it.

The hook instantiation is now moved to cached property.
@potiuk potiuk force-pushed the fix-azure-batch-hook-instantiation branch from 964d763 to c84eaaa Compare August 25, 2023 14:03
@@ -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

@potiuk
Copy link
Member Author

potiuk commented Aug 25, 2023

Tests are passing. Merging.

@potiuk potiuk merged commit 38f2737 into apache:main Aug 25, 2023
@potiuk potiuk deleted the fix-azure-batch-hook-instantiation branch August 25, 2023 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants