Skip to content

Commit cfe32c2

Browse files
xinlian12annie-mac
andauthored
resolve comments from API review (Azure#38352)
Co-authored-by: annie-mac <[email protected]>
1 parent 722cf59 commit cfe32c2

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/_vector_session_token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"""
2424

2525
from . import exceptions
26-
from .http_constants import StatusCodes
26+
from .http_constants import StatusCodes as _StatusCodes
2727

2828

2929
class VectorSessionToken(object):
@@ -119,7 +119,7 @@ def merge(self, other):
119119

120120
if self.version == other.version and len(self.local_lsn_by_region) != len(other.local_lsn_by_region):
121121
raise exceptions.CosmosHttpResponseError(
122-
status_code=StatusCodes.INTERNAL_SERVER_ERROR,
122+
status_code=_StatusCodes.INTERNAL_SERVER_ERROR,
123123
message=("Compared session tokens '%s' and '%s' have unexpected regions."
124124
% (self.session_token, other.session_token))
125125
)
@@ -146,7 +146,7 @@ def merge(self, other):
146146
highest_local_lsn_by_region[region_id] = max(local_lsn1, local_lsn2)
147147
elif self.version == other.version:
148148
raise exceptions.CosmosHttpResponseError(
149-
status_code=StatusCodes.INTERNAL_SERVER_ERROR,
149+
status_code=_StatusCodes.INTERNAL_SERVER_ERROR,
150150
message=("Compared session tokens '%s' and '%s' have unexpected regions."
151151
% (self.session_token, other.session_token))
152152
)

sdk/cosmos/azure-cosmos/azure/cosmos/database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from ._base import build_options, _set_throughput_options, _deserialize_throughput, _replace_throughput
3535
from .container import ContainerProxy
3636
from .offer import Offer, ThroughputProperties
37-
from .http_constants import StatusCodes
37+
from .http_constants import StatusCodes as _StatusCodes
3838
from .exceptions import CosmosResourceNotFoundError
3939
from .user import UserProxy
4040
from .documents import IndexingMode
@@ -826,7 +826,7 @@ def get_throughput(self, **kwargs: Any) -> ThroughputProperties:
826826
throughput_properties = list(self.client_connection.QueryOffers(query_spec, **kwargs))
827827
if not throughput_properties:
828828
raise CosmosResourceNotFoundError(
829-
status_code=StatusCodes.NOT_FOUND,
829+
status_code=_StatusCodes.NOT_FOUND,
830830
message="Could not find ThroughputProperties for database " + self.database_link)
831831

832832
if response_hook:
@@ -859,7 +859,7 @@ def replace_throughput(
859859
throughput_properties = list(self.client_connection.QueryOffers(query_spec))
860860
if not throughput_properties:
861861
raise CosmosResourceNotFoundError(
862-
status_code=StatusCodes.NOT_FOUND,
862+
status_code=_StatusCodes.NOT_FOUND,
863863
message="Could not find ThroughputProperties for database " + self.database_link)
864864
new_offer = throughput_properties[0].copy()
865865
_replace_throughput(throughput=throughput, new_throughput_properties=new_offer)

sdk/cosmos/azure-cosmos/azure/cosmos/exceptions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
ResourceNotFoundError
2929
)
3030
from . import http_constants
31-
from .http_constants import StatusCodes, SubStatusCodes
31+
from .http_constants import StatusCodes as _StatusCode, SubStatusCodes as _SubStatusCodes
3232

3333
class CosmosHttpResponseError(HttpResponseError):
3434
"""An HTTP request to the Azure Cosmos database service has failed."""
@@ -136,21 +136,21 @@ def __init__(self, **kwargs):
136136
super(CosmosClientTimeoutError, self).__init__(message, **kwargs)
137137

138138
def _partition_range_is_gone(e):
139-
if (e.status_code == http_constants.StatusCodes.GONE
140-
and e.sub_status == http_constants.SubStatusCodes.PARTITION_KEY_RANGE_GONE):
139+
if (e.status_code == _StatusCode.GONE
140+
and e.sub_status == _SubStatusCodes.PARTITION_KEY_RANGE_GONE):
141141
return True
142142
return False
143143

144144

145145
def _container_recreate_exception(e) -> bool:
146-
is_bad_request = e.status_code == http_constants.StatusCodes.BAD_REQUEST
147-
is_collection_rid_mismatch = e.sub_status == http_constants.SubStatusCodes.COLLECTION_RID_MISMATCH
146+
is_bad_request = e.status_code == _StatusCode.BAD_REQUEST
147+
is_collection_rid_mismatch = e.sub_status == _SubStatusCodes.COLLECTION_RID_MISMATCH
148148

149-
is_not_found = e.status_code == http_constants.StatusCodes.NOT_FOUND
150-
is_throughput_not_found = e.sub_status == http_constants.SubStatusCodes.THROUGHPUT_OFFER_NOT_FOUND
149+
is_not_found = e.status_code == _StatusCode.NOT_FOUND
150+
is_throughput_not_found = e.sub_status == _SubStatusCodes.THROUGHPUT_OFFER_NOT_FOUND
151151

152152
return (is_bad_request and is_collection_rid_mismatch) or (is_not_found and is_throughput_not_found)
153153

154154

155155
def _is_partition_split_or_merge(e):
156-
return e.status_code == StatusCodes.GONE and e.status_code == SubStatusCodes.COMPLETING_SPLIT
156+
return e.status_code == _StatusCode.GONE and e.status_code == _SubStatusCodes.COMPLETING_SPLIT

0 commit comments

Comments
 (0)