Skip to content

Commit

Permalink
[Tables] remove client side validation of entity (Azure#18267)
Browse files Browse the repository at this point in the history
* removed client side validation of entity

* fixes to try/catch

* removing comments

* using _decode_error
  • Loading branch information
seankane-msft authored May 19, 2021
1 parent 6bd591d commit 75ddfe3
Show file tree
Hide file tree
Showing 16 changed files with 478 additions and 130 deletions.
24 changes: 16 additions & 8 deletions sdk/tables/azure-data-tables/azure/data/tables/_table_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
from urlparse import urlparse # type: ignore
from urllib2 import unquote # type: ignore

from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
from azure.core.exceptions import HttpResponseError
from azure.core.paging import ItemPaged
from azure.core.tracing.decorator import distributed_trace

from ._deserialize import _convert_to_entity, _trim_service_metadata
from ._entity import TableEntity
from ._error import _process_table_error, _validate_table_name
from ._error import (
_process_table_error,
_validate_table_name,
_reraise_error,
_decode_error
)
from ._generated.models import (
SignedIdentifier,
TableProperties,
Expand Down Expand Up @@ -379,10 +384,7 @@ def create_entity(
:dedent: 12
:caption: Creating and adding an entity to a Table
"""
if "PartitionKey" in entity and "RowKey" in entity:
entity = _add_entity_properties(entity)
else:
raise ValueError("PartitionKey and RowKey were not provided in entity")
entity = _add_entity_properties(entity)
try:
metadata, _ = self._client.table.insert_entity(
table=self.table_name,
Expand All @@ -391,8 +393,14 @@ def create_entity(
**kwargs
)
return _trim_service_metadata(metadata)
except ResourceNotFoundError as error:
_process_table_error(error)
except HttpResponseError as error:
decoded = _decode_error(error.response, error.message)
if decoded.error_code == "PropertiesNeedValue":
if entity.get("PartitionKey") is None:
raise ValueError("PartitionKey must be present in an entity")
if entity.get("RowKey") is None:
raise ValueError("RowKey must be present in an entity")
_reraise_error(error)

@distributed_trace
def update_entity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential
from azure.core.async_paging import AsyncItemPaged
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError
from azure.core.exceptions import HttpResponseError
from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async

Expand All @@ -23,14 +23,19 @@
from .._models import AccessPolicy
from .._serialize import serialize_iso, _parameter_filter_substitution
from .._deserialize import _return_headers_and_deserialized
from .._error import _process_table_error, _validate_table_name
from .._error import (
_process_table_error,
_validate_table_name,
_decode_error,
_reraise_error
)
from .._models import UpdateMode
from .._deserialize import _convert_to_entity, _trim_service_metadata
from .._serialize import _add_entity_properties, _get_match_headers
from .._table_client import EntityType, TransactionOperationType
from ._base_client_async import AsyncTablesBaseClient
from ._models import TableEntityPropertiesPaged
from ._table_batch_async import TableBatchOperations
from .._table_client import EntityType, TransactionOperationType


class TableClient(AsyncTablesBaseClient):
Expand Down Expand Up @@ -368,10 +373,7 @@ async def create_entity(
:dedent: 8
:caption: Adding an entity to a Table
"""
if "PartitionKey" in entity and "RowKey" in entity:
entity = _add_entity_properties(entity)
else:
raise ValueError("PartitionKey and RowKey were not provided in entity")
entity = _add_entity_properties(entity)
try:
metadata, _ = await self._client.table.insert_entity(
table=self.table_name,
Expand All @@ -380,8 +382,15 @@ async def create_entity(
**kwargs
)
return _trim_service_metadata(metadata)
except ResourceNotFoundError as error:
_process_table_error(error)
except HttpResponseError as error:
decoded = _decode_error(error.response, error.message)
if decoded.error_code == "PropertiesNeedValue":
if entity.get("PartitionKey") is None:
raise ValueError("PartitionKey must be present in an entity")
if entity.get("RowKey") is None:
raise ValueError("RowKey must be present in an entity")
_reraise_error(error)


@distributed_trace_async
async def update_entity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:54:53 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:54:53 GMT
x-ms-version:
- '2019-02-02'
method: POST
Expand All @@ -33,7 +33,7 @@ interactions:
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:54:53 GMT
location:
- https://fake_table_account.table.core.windows.net/Tables('uttabled41f1395')
server:
Expand All @@ -47,6 +47,53 @@ interactions:
status:
code: 201
message: Created
- request:
body: '{"RowKey": "rk", "RowKey@odata.type": "Edm.String"}'
headers:
Accept:
- application/json;odata=minimalmetadata
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '51'
Content-Type:
- application/json;odata=nometadata
DataServiceVersion:
- '3.0'
Date:
- Fri, 23 Apr 2021 17:54:54 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 23 Apr 2021 17:54:54 GMT
x-ms-version:
- '2019-02-02'
method: POST
uri: https://fake_table_account.table.core.windows.net/uttabled41f1395
response:
body:
string: '{"odata.error":{"code":"PropertiesNeedValue","message":{"lang":"en-US","value":"The
values are not specified for all properties in the entity.\nRequestId:e81fe51f-c002-003c-2969-38f3e3000000\nTime:2021-04-23T17:54:54.3641239Z"}}}'
headers:
cache-control:
- no-cache
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 23 Apr 2021 17:54:53 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-ms-version:
- '2019-02-02'
status:
code: 400
message: Bad Request
- request:
body: null
headers:
Expand All @@ -59,11 +106,11 @@ interactions:
Content-Length:
- '0'
Date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:54:54 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:54:54 GMT
x-ms-version:
- '2019-02-02'
method: DELETE
Expand All @@ -77,7 +124,7 @@ interactions:
content-length:
- '0'
date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:54:53 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-content-type-options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:57:34 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:09:08 GMT
- Fri, 23 Apr 2021 17:57:34 GMT
x-ms-version:
- '2019-02-02'
method: POST
Expand All @@ -33,7 +33,7 @@ interactions:
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:57:35 GMT
location:
- https://fake_table_account.table.core.windows.net/Tables('uttabled4231397')
server:
Expand All @@ -47,6 +47,53 @@ interactions:
status:
code: 201
message: Created
- request:
body: '{"PartitionKey": "pk", "PartitionKey@odata.type": "Edm.String"}'
headers:
Accept:
- application/json;odata=minimalmetadata
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '63'
Content-Type:
- application/json;odata=nometadata
DataServiceVersion:
- '3.0'
Date:
- Fri, 23 Apr 2021 17:57:35 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 23 Apr 2021 17:57:35 GMT
x-ms-version:
- '2019-02-02'
method: POST
uri: https://fake_table_account.table.core.windows.net/uttabled4231397
response:
body:
string: '{"odata.error":{"code":"PropertiesNeedValue","message":{"lang":"en-US","value":"The
values are not specified for all properties in the entity.\nRequestId:ea3a5369-2002-001b-5b6a-38e427000000\nTime:2021-04-23T17:57:35.5932700Z"}}}'
headers:
cache-control:
- no-cache
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 23 Apr 2021 17:57:35 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-ms-version:
- '2019-02-02'
status:
code: 400
message: Bad Request
- request:
body: null
headers:
Expand All @@ -59,11 +106,11 @@ interactions:
Content-Length:
- '0'
Date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:57:35 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:57:35 GMT
x-ms-version:
- '2019-02-02'
method: DELETE
Expand All @@ -77,7 +124,7 @@ interactions:
content-length:
- '0'
date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:57:35 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-content-type-options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:03 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:03 GMT
x-ms-version:
- '2019-02-02'
method: POST
Expand All @@ -33,7 +33,7 @@ interactions:
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:03 GMT
location:
- https://fake_table_account.table.core.windows.net/Tables('uttablee10d18a6')
server:
Expand Down Expand Up @@ -66,26 +66,26 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:04 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:04 GMT
x-ms-version:
- '2019-02-02'
method: POST
uri: https://fake_table_account.table.core.windows.net/uttablee10d18a6
response:
body:
string: '{"odata.error":{"code":"PropertyNameTooLong","message":{"lang":"en-US","value":"The
property name exceeds the maximum allowed length (255).\nRequestId:f5282dfd-6002-0035-3f60-d5cf0d000000\nTime:2020-12-18T17:09:10.2909098Z"}}}'
property name exceeds the maximum allowed length (255).\nRequestId:a1de1e90-d002-007d-6b68-38ab07000000\nTime:2021-04-23T17:43:04.3558935Z"}}}'
headers:
cache-control:
- no-cache
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:03 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
Expand All @@ -109,11 +109,11 @@ interactions:
Content-Length:
- '0'
Date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:04 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b7 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:04 GMT
x-ms-version:
- '2019-02-02'
method: DELETE
Expand All @@ -127,7 +127,7 @@ interactions:
content-length:
- '0'
date:
- Fri, 18 Dec 2020 17:09:09 GMT
- Fri, 23 Apr 2021 17:43:04 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-content-type-options:
Expand Down
Loading

0 comments on commit 75ddfe3

Please sign in to comment.