-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Consistent returns #13245
Consistent returns #13245
Changes from 11 commits
ccafe0f
4b1f75a
c21fd4c
20cb21a
e4de1d5
d7f1f00
7be28fc
94b7415
ba82b25
1499b47
2a71664
56bfcdd
1b0a191
1d52074
ade3d40
c10926d
49c0137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
from ._deserialize import _return_headers_and_deserialized | ||
from ._error import _process_table_error | ||
from ._version import VERSION | ||
from ._models import TableEntityPropertiesPaged, UpdateMode, TableItem | ||
from ._models import TableEntityPropertiesPaged, UpdateMode | ||
|
||
|
||
class TableClient(TableClientBase): | ||
|
@@ -180,17 +180,19 @@ def create_table( | |
self, | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> TableItem | ||
# type: (...) -> Dict[str,str] | ||
"""Creates a new table under the current account. | ||
|
||
:return: TableItem created | ||
:rtype: TableItem | ||
:return: Dictionary of response headers from service | ||
:rtype: Dict[str,str] | ||
:raises: ~azure.core.exceptions.HttpResponseError | ||
""" | ||
table_properties = TableProperties(table_name=self.table_name, **kwargs) | ||
try: | ||
table = self._client.table.create(table_properties) | ||
return TableItem(table=table) | ||
metadata, _ = self._client.table.create( | ||
table_properties, | ||
cls=kwargs.pop('cls', _return_headers_and_deserialized)) | ||
return metadata | ||
except HttpResponseError as error: | ||
_process_table_error(error) | ||
|
||
|
@@ -250,29 +252,27 @@ def create_entity( | |
entity, # type: Union[TableEntity, dict[str,str]] | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> TableEntity | ||
# type: (...) -> dict[str,str] | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Insert entity in a table. | ||
|
||
:param entity: The properties for the table entity. | ||
:type entity: Union[TableEntity, dict[str,str]] | ||
:return: TableEntity mapping str to azure.data.tables.EntityProperty | ||
:rtype: ~azure.data.tables.TableEntity | ||
:return: Dictionary mapping response headers from the service | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:rtype: dict[str,str] | ||
:raises: ~azure.core.exceptions.HttpResponseError | ||
""" | ||
|
||
if "PartitionKey" in entity and "RowKey" in entity: | ||
entity = _add_entity_properties(entity) | ||
# TODO: Remove - and run test to see what happens with the service | ||
else: | ||
raise ValueError('PartitionKey and RowKey were not provided in entity') | ||
try: | ||
inserted_entity = self._client.table.insert_entity( | ||
metadata, _ = self._client.table.insert_entity( | ||
table=self.table_name, | ||
table_entity_properties=entity, | ||
**kwargs | ||
) | ||
properties = _convert_to_entity(inserted_entity) | ||
return properties | ||
cls=kwargs.pop('cls', _return_headers_and_deserialized), | ||
**kwargs) | ||
return metadata | ||
except ResourceNotFoundError as error: | ||
_process_table_error(error) | ||
|
||
|
@@ -283,7 +283,7 @@ def update_entity( # pylint:disable=R1710 | |
mode=UpdateMode.MERGE, # type: UpdateMode | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
# type: (...) -> Dict[str,str] | ||
"""Update entity in a table. | ||
|
||
:param entity: The properties for the table entity. | ||
|
@@ -294,8 +294,8 @@ def update_entity( # pylint:disable=R1710 | |
:keyword str row_key: The row key of the entity. | ||
:keyword str etag: Etag of the entity | ||
:keyword ~azure.core.MatchConditions match_condition: MatchCondition | ||
:return: None | ||
:rtype: None | ||
:return: Dictionary mapping response headers from the service | ||
:rtype: dict[str,str | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:raises: ~azure.core.exceptions.HttpResponseError | ||
""" | ||
|
||
|
@@ -307,20 +307,28 @@ def update_entity( # pylint:disable=R1710 | |
row_key = entity['RowKey'] | ||
entity = _add_entity_properties(entity) | ||
try: | ||
metadata = None | ||
if mode is UpdateMode.REPLACE: | ||
self._client.table.update_entity( | ||
metadata, _ = self._client.table.update_entity( | ||
table=self.table_name, | ||
partition_key=partition_key, | ||
row_key=row_key, | ||
table_entity_properties=entity, | ||
if_match=if_match or if_not_match or "*", | ||
cls=kwargs.pop('cls', _return_headers_and_deserialized), | ||
**kwargs) | ||
elif mode is UpdateMode.MERGE: | ||
self._client.table.merge_entity(table=self.table_name, partition_key=partition_key, | ||
row_key=row_key, if_match=if_match or if_not_match or "*", | ||
table_entity_properties=entity, **kwargs) | ||
metadata, _ = self._client.table.merge_entity( | ||
table=self.table_name, | ||
partition_key=partition_key, | ||
row_key=row_key, | ||
if_match=if_match or if_not_match or "*", | ||
table_entity_properties=entity, | ||
cls=kwargs.pop('cls', _return_headers_and_deserialized), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @annatisch had mentioned before that she prefers something more like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way it currently is if the user passes in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wont be passed to the service - as this parameter deals with client-side behaviour. |
||
**kwargs) | ||
else: | ||
raise ValueError('Mode type is not supported') | ||
return metadata | ||
except HttpResponseError as error: | ||
_process_table_error(error) | ||
|
||
|
@@ -395,15 +403,15 @@ def get_entity( | |
row_key, # type: str | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> TableEntity | ||
# type: (...) -> Dict[str,str] | ||
"""Queries entities in a table. | ||
|
||
:param partition_key: The partition key of the entity. | ||
:type partition_key: str | ||
:param row_key: The row key of the entity. | ||
:type row_key: str | ||
:return: Entity mapping str to azure.data.tables.EntityProperty | ||
:rtype: ~azure.data.tables.TableEntity | ||
:return: Dictionary mapping response headers from the service | ||
:rtype: dict[str,str | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:raises: ~azure.core.exceptions.HttpResponseError | ||
""" | ||
try: | ||
|
@@ -424,15 +432,15 @@ def upsert_entity( # pylint:disable=R1710 | |
mode=UpdateMode.MERGE, # type: UpdateMode | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
# type: (...) -> Dict[str,str] | ||
"""Update/Merge or Insert entity into table. | ||
|
||
:param entity: The properties for the table entity. | ||
:type entity: Union[TableEntity, dict[str,str]] | ||
:param mode: Merge or Replace and Insert on fail | ||
:type mode: ~azure.data.tables.UpdateMode | ||
:return: None | ||
:rtype: None | ||
:return: Dictionary mapping response headers from the service | ||
:rtype: dict[str,str | ||
:raises: ~azure.core.exceptions.HttpResponseError | ||
""" | ||
|
||
|
@@ -441,25 +449,29 @@ def upsert_entity( # pylint:disable=R1710 | |
entity = _add_entity_properties(entity) | ||
|
||
try: | ||
metadata = None | ||
if mode is UpdateMode.MERGE: | ||
self._client.table.merge_entity( | ||
metadata, _ = self._client.table.merge_entity( | ||
table=self.table_name, | ||
partition_key=partition_key, | ||
row_key=row_key, | ||
table_entity_properties=entity, | ||
cls=kwargs.pop('cls', _return_headers_and_deserialized), | ||
**kwargs | ||
) | ||
elif mode is UpdateMode.REPLACE: | ||
self._client.table.update_entity( | ||
metadata, _ = self._client.table.update_entity( | ||
table=self.table_name, | ||
partition_key=partition_key, | ||
row_key=row_key, | ||
table_entity_properties=entity, | ||
cls=kwargs.pop('cls', _return_headers_and_deserialized), | ||
**kwargs) | ||
else: | ||
raise ValueError('Mode type is not supported') | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return metadata | ||
except ResourceNotFoundError: | ||
self.create_entity( | ||
return self.create_entity( | ||
partition_key=partition_key, | ||
row_key=row_key, | ||
table_entity_properties=entity, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's in this metadata? Do we need to clean out unnecessary information?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The returned metadata has these keys:
client_request_id
,request_id
,version
,date
, andetag
always. Oncreate_entity
the service also returnspreference_applied
andcontent_type
.client_request_id
,request_id
, andpreference_applied
are allNone
in the tests