Skip to content

Commit 6bc810e

Browse files
[Tables] delete_entity takes an entity instead of row and partition key (#18269)
1 parent 59ecfd8 commit 6bc810e

15 files changed

+2575
-44
lines changed

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# --------------------------------------------------------------------------
66

77
import functools
8-
from typing import Optional, Any, Union, List, Tuple, Dict, Mapping, Iterable
8+
from typing import Optional, Any, Union, List, Tuple, Dict, Mapping, Iterable, overload
99
try:
1010
from urllib.parse import urlparse, unquote
1111
except ImportError:
@@ -273,14 +273,19 @@ def delete_table(
273273
except HttpResponseError as error:
274274
_process_table_error(error)
275275

276+
@overload
277+
def delete_entity(self, partition_key, row_key, **kwargs):
278+
# type: (str, str, Any) -> None
279+
pass
280+
281+
@overload
282+
def delete_entity(self, entity, **kwargs):
283+
# type: (Union[TableEntity, Mapping[str, Any]], Any) -> None
284+
pass
285+
276286
@distributed_trace
277-
def delete_entity(
278-
self,
279-
partition_key, # type: str
280-
row_key, # type: str
281-
**kwargs # type: Any
282-
):
283-
# type: (...) -> None
287+
def delete_entity(self, *args, **kwargs):
288+
# type: (Union[TableEntity, str], Any) -> None
284289
"""Deletes the specified entity in a table.
285290
286291
:param partition_key: The partition key of the entity.
@@ -303,6 +308,20 @@ def delete_entity(
303308
:dedent: 8
304309
:caption: Deleting an entity to a Table
305310
"""
311+
try:
312+
entity = kwargs.pop('entity', None)
313+
if not entity:
314+
entity = args[0]
315+
partition_key = entity['PartitionKey']
316+
row_key = entity['RowKey']
317+
except (TypeError, IndexError):
318+
partition_key = kwargs.pop('partition_key', None)
319+
if not partition_key:
320+
partition_key = args[0]
321+
row_key = kwargs.pop("row_key", None)
322+
if not row_key:
323+
row_key = args[1]
324+
306325

307326
if_match, _ = _get_match_headers(
308327
kwargs=dict(

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# license information.
55
# --------------------------------------------------------------------------
66
import functools
7-
from typing import List, Union, Any, Optional, Mapping, Iterable
7+
from typing import List, Union, Any, Optional, Mapping, Iterable, Dict, overload
88
try:
99
from urllib.parse import urlparse, unquote
1010
except ImportError:
@@ -264,13 +264,16 @@ async def delete_table(self, **kwargs) -> None:
264264
except HttpResponseError as error:
265265
_process_table_error(error)
266266

267+
@overload
268+
async def delete_entity(self, partition_key: str, row_key: str, **kwargs: Any) -> None:
269+
...
270+
271+
@overload
272+
async def delete_entity(self, entity: Union[TableEntity, Mapping[str, Any]], **kwargs: Any) -> None:
273+
...
274+
267275
@distributed_trace_async
268-
async def delete_entity(
269-
self,
270-
partition_key: str,
271-
row_key: str,
272-
**kwargs
273-
) -> None:
276+
async def delete_entity(self, *args: Union[TableEntity, str], **kwargs: Any) -> None:
274277
"""Deletes the specified entity in a table.
275278
276279
:param partition_key: The partition key of the entity.
@@ -293,6 +296,20 @@ async def delete_entity(
293296
:dedent: 8
294297
:caption: Adding an entity to a Table
295298
"""
299+
try:
300+
entity = kwargs.pop('entity', None)
301+
if not entity:
302+
entity = args[0]
303+
partition_key = entity['PartitionKey']
304+
row_key = entity['RowKey']
305+
except (TypeError, IndexError):
306+
partition_key = kwargs.pop('partition_key', None)
307+
if not partition_key:
308+
partition_key = args[0]
309+
row_key = kwargs.pop("row_key", None)
310+
if not row_key:
311+
row_key = args[1]
312+
296313
if_match, _ = _get_match_headers(
297314
kwargs=dict(
298315
kwargs,

0 commit comments

Comments
 (0)