Skip to content

Commit

Permalink
[Tables] Fix bug in update mode (#20264)
Browse files Browse the repository at this point in the history
* Fix bug in update mode

* Updated codeowners
  • Loading branch information
annatisch authored and iscai-msft committed Sep 29, 2021
1 parent eab3162 commit 86d042d
Show file tree
Hide file tree
Showing 10 changed files with 637 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
/sdk/translation/ @kristapratico @mohamedshabanofficial

# PRLabel: %Tables
/sdk/tables/ @seankane-msft
/sdk/tables/ @annatisch @YalinLi0312

# PRLabel: %Media
/sdk/media/ @naiteeks @bennage @giakas
Expand Down
2 changes: 2 additions & 0 deletions sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Resolved bug where strings couldn't be used instead of enum value for entity Update Mode (#20247).

### Other Changes

- Bumped dependency on `msrest` to `>=0.6.21`
Expand Down
12 changes: 8 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 @@ -261,7 +261,7 @@ def update(
partition_key = temp["PartitionKey"]
row_key = temp["RowKey"]
temp = _add_entity_properties(temp)
if mode is UpdateMode.REPLACE:
if mode == UpdateMode.REPLACE:
self._batch_update_entity(
table=self.table_name,
partition_key=partition_key,
Expand All @@ -270,7 +270,7 @@ def update(
table_entity_properties=temp,
**kwargs
)
elif mode is UpdateMode.MERGE:
elif mode == UpdateMode.MERGE:
self._batch_merge_entity(
table=self.table_name,
partition_key=partition_key,
Expand All @@ -279,6 +279,8 @@ def update(
table_entity_properties=temp,
**kwargs
)
else:
raise ValueError("Mode type '{}' is not supported.".format(mode))

def _batch_update_entity(
self,
Expand Down Expand Up @@ -668,19 +670,21 @@ def upsert(
row_key = temp["RowKey"]
temp = _add_entity_properties(temp)

if mode is UpdateMode.MERGE:
if mode == UpdateMode.MERGE:
self._batch_merge_entity(
table=self.table_name,
partition_key=partition_key,
row_key=row_key,
table_entity_properties=temp,
**kwargs
)
elif mode is UpdateMode.REPLACE:
elif mode == UpdateMode.REPLACE:
self._batch_update_entity(
table=self.table_name,
partition_key=partition_key,
row_key=row_key,
table_entity_properties=temp,
**kwargs
)
else:
raise ValueError("Mode type '{}' is not supported.".format(mode))
10 changes: 5 additions & 5 deletions sdk/tables/azure-data-tables/azure/data/tables/_table_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def update_entity(
try:
metadata = None
content = None
if mode is UpdateMode.REPLACE:
if mode == UpdateMode.REPLACE:
metadata, content = self._client.table.update_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand All @@ -476,7 +476,7 @@ def update_entity(
cls=kwargs.pop("cls", _return_headers_and_deserialized),
**kwargs
)
elif mode is UpdateMode.MERGE:
elif mode == UpdateMode.MERGE:
metadata, content = self._client.table.merge_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand All @@ -487,7 +487,7 @@ def update_entity(
**kwargs
)
else:
raise ValueError("Mode type is not supported")
raise ValueError("Mode type '{}' is not supported.".format(mode))
except HttpResponseError as error:
_process_table_error(error)
return _trim_service_metadata(metadata, content=content) # type: ignore
Expand Down Expand Up @@ -654,7 +654,7 @@ def upsert_entity(
try:
metadata = None
content = None
if mode is UpdateMode.MERGE:
if mode == UpdateMode.MERGE:
metadata, content = self._client.table.merge_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand All @@ -663,7 +663,7 @@ def upsert_entity(
cls=kwargs.pop("cls", _return_headers_and_deserialized),
**kwargs
)
elif mode is UpdateMode.REPLACE:
elif mode == UpdateMode.REPLACE:
metadata, content = self._client.table.update_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def update(
partition_key = temp["PartitionKey"]
row_key = temp["RowKey"]
temp = _add_entity_properties(temp)
if mode is UpdateMode.REPLACE:
if mode == UpdateMode.REPLACE:
self._batch_update_entity(
table=self.table_name,
partition_key=partition_key,
Expand All @@ -242,7 +242,7 @@ def update(
table_entity_properties=temp,
**kwargs
)
elif mode is UpdateMode.MERGE:
elif mode == UpdateMode.MERGE:
self._batch_merge_entity(
table=self.table_name,
partition_key=partition_key,
Expand All @@ -251,6 +251,8 @@ def update(
table_entity_properties=temp,
**kwargs
)
else:
raise ValueError("Mode type '{}' is not supported.".format(mode))

def _batch_update_entity(
self,
Expand Down Expand Up @@ -631,19 +633,21 @@ def upsert(
row_key = temp["RowKey"]
temp = _add_entity_properties(temp)

if mode is UpdateMode.MERGE:
if mode == UpdateMode.MERGE:
self._batch_merge_entity(
table=self.table_name,
partition_key=partition_key,
row_key=row_key,
table_entity_properties=temp,
**kwargs
)
elif mode is UpdateMode.REPLACE:
elif mode == UpdateMode.REPLACE:
self._batch_update_entity(
table=self.table_name,
partition_key=partition_key,
row_key=row_key,
table_entity_properties=temp,
**kwargs
)
else:
raise ValueError("Mode type '{}' is not supported.".format(mode))
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ async def update_entity(
try:
metadata = None
content = None
if mode is UpdateMode.REPLACE:
if mode == UpdateMode.REPLACE:
metadata, content = await self._client.table.update_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand All @@ -458,7 +458,7 @@ async def update_entity(
cls=kwargs.pop("cls", _return_headers_and_deserialized),
**kwargs
)
elif mode is UpdateMode.MERGE:
elif mode == UpdateMode.MERGE:
metadata, content = await self._client.table.merge_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand All @@ -469,7 +469,7 @@ async def update_entity(
**kwargs
)
else:
raise ValueError("Mode type is not supported")
raise ValueError("Mode type '{}' is not supported.".format(mode))
except HttpResponseError as error:
_process_table_error(error)
return _trim_service_metadata(metadata, content=content) # type: ignore
Expand Down Expand Up @@ -632,7 +632,7 @@ async def upsert_entity(
try:
metadata = None
content = None
if mode is UpdateMode.MERGE:
if mode == UpdateMode.MERGE:
metadata, content = await self._client.table.merge_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand All @@ -641,7 +641,7 @@ async def upsert_entity(
cls=kwargs.pop("cls", _return_headers_and_deserialized),
**kwargs
)
elif mode is UpdateMode.REPLACE:
elif mode == UpdateMode.REPLACE:
metadata, content = await self._client.table.update_entity( # type: ignore
table=self.table_name,
partition_key=partition_key,
Expand Down
Loading

0 comments on commit 86d042d

Please sign in to comment.