Skip to content

Commit fa44dea

Browse files
authored
Fix typing contract for max_concurrency in Datalake client (#45631)
1 parent 1abb890 commit fa44dea

5 files changed

Lines changed: 85 additions & 2 deletions

File tree

sdk/storage/azure-storage-file-datalake/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/storage/azure-storage-file-datalake",
5-
"Tag": "python/storage/azure-storage-file-datalake_4ab697f017"
5+
"Tag": "python/storage/azure-storage-file-datalake_3d29de0db8"
66
}

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client_helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
get_mod_conditions,
2020
get_path_http_headers
2121
)
22+
from ._shared.constants import DEFAULT_MAX_CONCURRENCY
2223
from ._shared.request_handlers import get_length, read_length
2324
from ._shared.response_handlers import return_response_headers
2425
from ._shared.uploads import IterStreamer
@@ -124,7 +125,9 @@ def _upload_options(
124125
validate_content = kwargs.pop('validate_content', False)
125126
content_settings = kwargs.pop('content_settings', None)
126127
metadata = kwargs.pop('metadata', None)
127-
max_concurrency = kwargs.pop('max_concurrency', 1)
128+
max_concurrency = kwargs.pop('max_concurrency', None)
129+
if max_concurrency is None:
130+
max_concurrency = DEFAULT_MAX_CONCURRENCY
128131

129132
kwargs['properties'] = add_metadata_headers(metadata)
130133
kwargs['lease_access_conditions'] = get_access_conditions(kwargs.pop('lease', None))

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
DEFAULT_OAUTH_SCOPE = "/.default"
1818
STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"
1919

20+
DEFAULT_MAX_CONCURRENCY = 1
21+
2022
SERVICE_HOST_BASE = "core.windows.net"

sdk/storage/azure-storage-file-datalake/tests/test_file.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,27 @@ def test_upload_data_to_existing_file_with_permission_and_umask(self, **kwargs):
692692
assert data == downloaded_data
693693
assert prop['permissions'] == 'rwxrwxrwx'
694694

695+
@DataLakePreparer()
696+
@recorded_by_proxy
697+
def test_upload_data_with_none_max_concurrency(self, **kwargs):
698+
datalake_storage_account_name = kwargs.pop("datalake_storage_account_name")
699+
datalake_storage_account_key = kwargs.pop("datalake_storage_account_key")
700+
701+
self._setUp(datalake_storage_account_name, datalake_storage_account_key)
702+
directory_name = self._get_directory_reference()
703+
704+
# Create a directory to put the file under that
705+
directory_client = self.dsc.get_directory_client(self.file_system_name, directory_name)
706+
directory_client.create_directory()
707+
708+
file_client = directory_client.get_file_client('filename')
709+
data = self.get_random_bytes(100)
710+
# max_concurrency=None should not raise TypeError
711+
file_client.upload_data(data, overwrite=True, max_concurrency=None)
712+
713+
downloaded_data = file_client.download_file().readall()
714+
assert data == downloaded_data
715+
695716
@DataLakePreparer()
696717
@recorded_by_proxy
697718
def test_read_file(self, **kwargs):
@@ -710,6 +731,24 @@ def test_read_file(self, **kwargs):
710731
downloaded_data = file_client.download_file().readall()
711732
assert data == downloaded_data
712733

734+
@DataLakePreparer()
735+
@recorded_by_proxy
736+
def test_read_file_with_none_max_concurrency(self, **kwargs):
737+
datalake_storage_account_name = kwargs.pop("datalake_storage_account_name")
738+
datalake_storage_account_key = kwargs.pop("datalake_storage_account_key")
739+
740+
self._setUp(datalake_storage_account_name, datalake_storage_account_key)
741+
file_client = self._create_file_and_return_client()
742+
data = self.get_random_bytes(1024)
743+
744+
# upload data to file
745+
file_client.append_data(data, 0, len(data))
746+
file_client.flush_data(len(data))
747+
748+
# max_concurrency=None should not raise TypeError
749+
downloaded_data = file_client.download_file(max_concurrency=None).readall()
750+
assert data == downloaded_data
751+
713752
@pytest.mark.live_test_only
714753
@DataLakePreparer()
715754
def test_read_file_with_user_delegation_key(self, **kwargs):

sdk/storage/azure-storage-file-datalake/tests/test_file_async.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,27 @@ async def data_generator():
727727
result = await (await file_client.download_file()).readall()
728728
assert result == data*3
729729

730+
@DataLakePreparer()
731+
@recorded_by_proxy_async
732+
async def test_upload_data_with_none_max_concurrency(self, **kwargs):
733+
datalake_storage_account_name = kwargs.pop("datalake_storage_account_name")
734+
datalake_storage_account_key = kwargs.pop("datalake_storage_account_key")
735+
736+
await self._setUp(datalake_storage_account_name, datalake_storage_account_key)
737+
738+
# Create a directory to put the file under
739+
directory_name = self._get_directory_reference()
740+
directory_client = self.dsc.get_directory_client(self.file_system_name, directory_name)
741+
await directory_client.create_directory()
742+
743+
file_client = directory_client.get_file_client('filename')
744+
data = self.get_random_bytes(100)
745+
# max_concurrency=None should not raise TypeError
746+
await file_client.upload_data(data, overwrite=True, max_concurrency=None)
747+
748+
downloaded_data = await (await file_client.download_file()).readall()
749+
assert data == downloaded_data
750+
730751
@DataLakePreparer()
731752
@recorded_by_proxy_async
732753
async def test_read_file(self, **kwargs):
@@ -745,6 +766,24 @@ async def test_read_file(self, **kwargs):
745766
downloaded_data = await (await file_client.download_file()).readall()
746767
assert data == downloaded_data
747768

769+
@DataLakePreparer()
770+
@recorded_by_proxy_async
771+
async def test_read_file_with_none_max_concurrency(self, **kwargs):
772+
datalake_storage_account_name = kwargs.pop("datalake_storage_account_name")
773+
datalake_storage_account_key = kwargs.pop("datalake_storage_account_key")
774+
775+
await self._setUp(datalake_storage_account_name, datalake_storage_account_key)
776+
file_client = await self._create_file_and_return_client()
777+
data = self.get_random_bytes(1024)
778+
779+
# upload data to file
780+
await file_client.append_data(data, 0, len(data))
781+
await file_client.flush_data(len(data))
782+
783+
# max_concurrency=None should not raise TypeError
784+
downloaded_data = await (await file_client.download_file(max_concurrency=None)).readall()
785+
assert data == downloaded_data
786+
748787
@pytest.mark.live_test_only
749788
@DataLakePreparer()
750789
async def test_read_file_with_user_delegation_key(self, **kwargs):

0 commit comments

Comments
 (0)