Skip to content

[Tables] use etag from entity if match condition is given #18271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Added support for Azurite storage emulator
* Throws a `RequestTooLargeError` on transaction requests that return a 413 error code
* Added support for Int64 and Binary types in query filters
* On `update_entity` and `delete_entity` if no `etag` is supplied via kwargs, the `etag` in the entity will be used if it is in the entity.

## 12.0.0b6 (2021-04-06)
* Updated deserialization of datetime fields in entities to support preservation of the service format with additional decimal place.
Expand Down
25 changes: 21 additions & 4 deletions sdk/tables/azure-data-tables/azure/data/tables/_table_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,19 @@ def update(
self._verify_partition_key(entity)
temp = entity.copy()

match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
Expand Down Expand Up @@ -516,16 +524,25 @@ def delete(
partition_key = temp["PartitionKey"]
row_key = temp["RowKey"]

match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
)


self._batch_delete_entity(
table=self.table_name,
partition_key=partition_key,
Expand Down
22 changes: 18 additions & 4 deletions sdk/tables/azure-data-tables/azure/data/tables/_table_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,19 @@ def delete_entity(self, *args, **kwargs):
if not row_key:
row_key = args[1]

match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and entity and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
Expand Down Expand Up @@ -414,12 +421,19 @@ def update_entity(
:dedent: 8
:caption: Updating an already exiting entity in a Table
"""
match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,19 @@ def update(
self._verify_partition_key(entity)
temp = entity.copy()

match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
Expand Down Expand Up @@ -484,11 +492,20 @@ def delete(
temp = entity.copy()
partition_key = temp["PartitionKey"]
row_key = temp["RowKey"]

match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,24 @@ async def delete_entity(self, *args: Union[TableEntity, str], **kwargs: Any) ->
if not row_key:
row_key = args[1]

match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and entity and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
)

try:
await self._client.table.delete_entity(
table=self.table_name,
Expand Down Expand Up @@ -402,11 +411,19 @@ async def update_entity(
:dedent: 8
:caption: Querying entities from a TableClient
"""
match_condition = kwargs.pop("match_condition", None)
etag = kwargs.pop("etag", None)
if match_condition and entity and not etag:
try:
etag = entity.metadata.get("etag", None)
except (AttributeError, TypeError):
pass

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
etag=kwargs.pop("etag", None),
match_condition=kwargs.pop("match_condition", None),
etag=etag,
match_condition=match_condition,
),
etag_param="etag",
match_param="match_condition",
Expand Down
Loading