Nishieee commented on code in PR #67016:
URL: https://github.com/apache/airflow/pull/67016#discussion_r3259397503
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/wasb.py:
##########
@@ -271,6 +272,21 @@ def check_for_prefix(self, container_name: str, prefix:
str, **kwargs) -> bool:
blobs = self.get_blobs_list(container_name=container_name,
prefix=prefix, **kwargs)
return bool(blobs)
+ def check_for_container(self, container_name: str) -> bool:
+ """
+ Check if a container exists on Azure Blob Storage.
+
+ :param container_name: Name of the container.
+ :return: True if the container exists, False otherwise.
+ """
+ try:
+ container = self._get_container_client(container_name)
+ self.check_for_variable_type("container", container,
ContainerClient)
+ cast("ContainerClient", container).get_container_properties()
Review Comment:
If we switch `check_for_container` to use `exists()`, the hook unit tests in
`test_wasb.py` need small updates (same four tests, different mocks/assertions):
| Test | Change |
|------|--------|
| `test_check_for_container` | Assert `exists()` is called instead of
`get_container_properties()`. |
| `test_check_for_container_not_found` | Use `exists.return_value = False`
instead of `ResourceNotFoundError` on `get_container_properties()`. |
| `test_check_for_container_propagates_unexpected_errors` | Attach
`side_effect` to `exists()` instead of `get_container_properties()`. |
### Bundle tests
Bundle tests in `bundles/test_wasb.py` stay as-is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]