Skip to content

Commit 481e01f

Browse files
Fix TableClient.list_entities leaking unsupported kwargs to transport (#46137)
* Fix async TableClient.list_entities(query_filter=...) leaking kwarg to transport Fixes #46014. list_entities() was forwarding all **kwargs (including query_filter and parameters) into the generated operation's partial, causing them to leak to the aiohttp transport layer as unexpected kwargs. Now consumes query_filter/parameters before building the partial and passes the substituted filter value to the pager, matching query_entities() behavior. Fix applied to both sync and async clients. * Revise fix: reject query_filter with ValueError instead of forwarding it Per maintainer feedback, list_entities should not support query_filter. Instead of forwarding it as filter= to the pager, now raises a clear ValueError pointing users to query_entities for server-side filtering. Also replaces mypartition with pk001 in tests to pass cspell CI check. * Reject parameters-only kwargs in list_entities --------- Co-authored-by: Anna Tisch <8689453+annatisch@users.noreply.github.com>
1 parent de93304 commit 481e01f

4 files changed

Lines changed: 81 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ def list_entities(
539539
:rtype: An iterator of custom entity type.
540540
:raises: :class:`~azure.core.exceptions.HttpResponseError`
541541
"""
542+
if "query_filter" in kwargs or "parameters" in kwargs:
543+
raise ValueError(
544+
"'query_filter' and 'parameters' are not supported for 'list_entities'. "
545+
"Use 'query_entities' for server-side filtering."
546+
)
547+
542548
if select and not isinstance(select, str):
543549
select = ",".join(select)
544550

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,12 @@ def list_entities(
561561
:dedent: 16
562562
:caption: Listing all entities held within a table
563563
"""
564+
if "query_filter" in kwargs or "parameters" in kwargs:
565+
raise ValueError(
566+
"'query_filter' and 'parameters' are not supported for 'list_entities'. "
567+
"Use 'query_entities' for server-side filtering."
568+
)
569+
564570
if select and not isinstance(select, str):
565571
select = ",".join(select)
566572

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,3 +1050,36 @@ def test_use_development_storage(self):
10501050
assert tsc._primary_endpoint == "http://127.0.0.1:10002/devstoreaccount1"
10511051
assert tsc._secondary_endpoint == "http://127.0.0.1:10002/devstoreaccount1-secondary"
10521052
assert not tsc._cosmos_endpoint
1053+
1054+
def test_list_entities_rejects_query_filter(self):
1055+
"""Regression test: list_entities raises ValueError for query_filter instead of leaking to transport."""
1056+
credential = AzureNamedKeyCredential(
1057+
"fake_account", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
1058+
)
1059+
client = TableClient("https://fake_account.table.core.windows.net", "testtable", credential=credential)
1060+
1061+
with pytest.raises(ValueError, match="query_filter"):
1062+
client.list_entities(query_filter="PartitionKey eq 'pk001'")
1063+
client.close()
1064+
1065+
def test_list_entities_rejects_query_filter_with_parameters(self):
1066+
"""Regression test: list_entities raises ValueError when query_filter is passed with parameters."""
1067+
credential = AzureNamedKeyCredential(
1068+
"fake_account", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
1069+
)
1070+
client = TableClient("https://fake_account.table.core.windows.net", "testtable", credential=credential)
1071+
1072+
with pytest.raises(ValueError, match="query_entities"):
1073+
client.list_entities(query_filter="PartitionKey eq @pk", parameters={"pk": "pk001"})
1074+
client.close()
1075+
1076+
def test_list_entities_rejects_parameters_without_query_filter(self):
1077+
"""Regression test: list_entities raises ValueError when parameters are passed without query_filter."""
1078+
credential = AzureNamedKeyCredential(
1079+
"fake_account", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
1080+
)
1081+
client = TableClient("https://fake_account.table.core.windows.net", "testtable", credential=credential)
1082+
1083+
with pytest.raises(ValueError, match="parameters"):
1084+
client.list_entities(parameters={"pk": "pk001"})
1085+
client.close()

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,3 +1076,39 @@ def test_use_development_storage(self):
10761076
assert tsc._primary_endpoint == "http://127.0.0.1:10002/devstoreaccount1"
10771077
assert tsc._secondary_endpoint == "http://127.0.0.1:10002/devstoreaccount1-secondary"
10781078
assert not tsc._cosmos_endpoint
1079+
1080+
@pytest.mark.asyncio
1081+
async def test_list_entities_rejects_query_filter(self):
1082+
"""Regression test: list_entities raises ValueError for query_filter instead of leaking to transport."""
1083+
credential = AzureNamedKeyCredential(
1084+
"fake_account", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
1085+
)
1086+
client = TableClient("https://fake_account.table.core.windows.net", "testtable", credential=credential)
1087+
1088+
with pytest.raises(ValueError, match="query_filter"):
1089+
client.list_entities(query_filter="PartitionKey eq 'pk001'")
1090+
await client.close()
1091+
1092+
@pytest.mark.asyncio
1093+
async def test_list_entities_rejects_query_filter_with_parameters(self):
1094+
"""Regression test: list_entities raises ValueError when query_filter is passed with parameters."""
1095+
credential = AzureNamedKeyCredential(
1096+
"fake_account", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
1097+
)
1098+
client = TableClient("https://fake_account.table.core.windows.net", "testtable", credential=credential)
1099+
1100+
with pytest.raises(ValueError, match="query_entities"):
1101+
client.list_entities(query_filter="PartitionKey eq @pk", parameters={"pk": "pk001"})
1102+
await client.close()
1103+
1104+
@pytest.mark.asyncio
1105+
async def test_list_entities_rejects_parameters_without_query_filter(self):
1106+
"""Regression test: list_entities raises ValueError when parameters are passed without query_filter."""
1107+
credential = AzureNamedKeyCredential(
1108+
"fake_account", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
1109+
)
1110+
client = TableClient("https://fake_account.table.core.windows.net", "testtable", credential=credential)
1111+
1112+
with pytest.raises(ValueError, match="parameters"):
1113+
client.list_entities(parameters={"pk": "pk001"})
1114+
await client.close()

0 commit comments

Comments
 (0)