Skip to content

Commit 5a9e737

Browse files
author
Yalin Li
authored
[Tables] Fix a bug in submit_transaction() with empty operation list (Azure#31482)
1 parent d4f587c commit 5a9e737

File tree

7 files changed

+66
-2
lines changed

7 files changed

+66
-2
lines changed

sdk/tables/azure-data-tables/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
### Breaking Changes
99

1010
### Bugs Fixed
11+
* Fixed a bug when submitting transactions with an empty operation list. ([#31471](https://github.com/Azure/azure-sdk-for-python/issues/31471))
1112

1213
### Other Changes
1314
* Bumped minimum dependency on `azure-core` to `>=1.27.1`. ([#28918](https://github.com/Azure/azure-sdk-for-python/issues/28918))

sdk/tables/azure-data-tables/azure/data/tables/_table_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,10 @@ def submit_transaction(self, operations: Iterable[TransactionOperationType], **k
658658
"The value of 'operations' must be an iterator "
659659
"of Tuples. Please check documentation for correct Tuple format."
660660
) from exc
661-
return self._batch_send(self.table_name, *batched_requests.requests, **kwargs) # type: ignore
661+
662+
try:
663+
return self._batch_send(self.table_name, *batched_requests.requests, **kwargs) # type: ignore
664+
except HttpResponseError as ex:
665+
if ex.status_code == 400 and not batched_requests.requests:
666+
return []
667+
raise

sdk/tables/azure-data-tables/azure/data/tables/aio/_table_client_async.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,4 +682,9 @@ async def submit_transaction(
682682
"of Tuples. Please check documentation for correct Tuple format."
683683
) from exc
684684

685-
return await self._batch_send(self.table_name, *batched_requests.requests, **kwargs)
685+
try:
686+
return await self._batch_send(self.table_name, *batched_requests.requests, **kwargs)
687+
except HttpResponseError as ex:
688+
if ex.status_code == 400 and not batched_requests.requests:
689+
return []
690+
raise

sdk/tables/azure-data-tables/tests/test_table_batch.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,19 @@ def test_batch_with_specialchar_partitionkey(self, tables_storage_account_name,
965965
finally:
966966
self._tear_down()
967967

968+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
969+
@pytest.mark.live_test_only
970+
@tables_decorator
971+
@recorded_by_proxy
972+
def test_empty_batch(self, tables_storage_account_name, tables_primary_storage_account_key):
973+
url = self.account_url(tables_storage_account_name, "table")
974+
table_name = self.get_resource_name("mytable")
975+
with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
976+
client.create_table()
977+
result = client.submit_transaction([])
978+
assert result == []
979+
client.delete_table()
980+
968981
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
969982
@pytest.mark.live_test_only
970983
@tables_decorator

sdk/tables/azure-data-tables/tests/test_table_batch_async.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,19 @@ async def generate_entities(count):
889889
finally:
890890
await self._tear_down()
891891

892+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
893+
@pytest.mark.live_test_only
894+
@tables_decorator_async
895+
@recorded_by_proxy_async
896+
async def test_empty_batch(self, tables_storage_account_name, tables_primary_storage_account_key):
897+
url = self.account_url(tables_storage_account_name, "table")
898+
table_name = self.get_resource_name("mytable")
899+
async with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
900+
await client.create_table()
901+
result = await client.submit_transaction([])
902+
assert result == []
903+
await client.delete_table()
904+
892905
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
893906
@pytest.mark.live_test_only
894907
@tables_decorator_async

sdk/tables/azure-data-tables/tests/test_table_batch_cosmos.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,19 @@ def test_batch_with_specialchar_partitionkey(self, tables_cosmos_account_name, t
690690
finally:
691691
self._tear_down()
692692

693+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
694+
@pytest.mark.live_test_only
695+
@cosmos_decorator
696+
@recorded_by_proxy
697+
def test_empty_batch(self, tables_cosmos_account_name, tables_primary_cosmos_account_key):
698+
url = self.account_url(tables_cosmos_account_name, "cosmos")
699+
table_name = self.get_resource_name("mytable")
700+
with TableClient(url, table_name, credential=tables_primary_cosmos_account_key) as client:
701+
# client.create_table()
702+
result = client.submit_transaction([])
703+
assert result == []
704+
client.delete_table()
705+
693706
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
694707
@pytest.mark.live_test_only
695708
@cosmos_decorator

sdk/tables/azure-data-tables/tests/test_table_batch_cosmos_async.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,19 @@ async def generate_entities(count):
797797
finally:
798798
await self._tear_down()
799799

800+
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
801+
@pytest.mark.live_test_only
802+
@cosmos_decorator_async
803+
@recorded_by_proxy_async
804+
async def test_empty_batch(self, tables_cosmos_account_name, tables_primary_cosmos_account_key):
805+
url = self.account_url(tables_cosmos_account_name, "cosmos")
806+
table_name = self.get_resource_name("mytable")
807+
async with TableClient(url, table_name, credential=tables_primary_cosmos_account_key) as client:
808+
await client.create_table()
809+
result = await client.submit_transaction([])
810+
assert result == []
811+
await client.delete_table()
812+
800813
# Playback doesn't work as test proxy issue: https://github.com/Azure/azure-sdk-tools/issues/2900
801814
@pytest.mark.live_test_only
802815
@cosmos_decorator_async

0 commit comments

Comments
 (0)