Skip to content

Commit 433d3db

Browse files
qiaozhaAutorestCI
andauthored
release-for-mgmt-cosmosdb-0.16.0 (Azure#12842)
Co-authored-by: Azure SDK Bot <[email protected]>
1 parent c60e2dd commit 433d3db

File tree

53 files changed

+3265
-907
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3265
-907
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 4.0.1 (Unreleased)
2+
3+
- Added deprecation warning for "lazy" indexing mode. The backend no longer allows creating containers with this mode and will set them to consistent instead.
4+
5+
**New features**
6+
- Added the ability to set the analytical storage TTL when creating a new container.
7+
8+
**Bug fixes**
9+
- Fixed support for dicts as inputs for get_client APIs.
10+
- Fixed Python 2/3 compatibility in query iterators.
11+
- Fixed type hint error. Issue #12570 - Thanks @sl-sandy.
12+
- Fixed bug where options headers were not added to upsert_item function. Issue #11791 - thank you @aalapatirvbd.
13+
- Fixed error raised when a non string ID is used in an item. It now raises TypeError rather than AttributeError. Issue #11793 - thank you @Rabbit994.
14+
15+
116
## 4.0.0 (2020-05-20)
217

318
- Stable release.
@@ -235,4 +250,3 @@ Version 4.0.0b1 is the first preview of our efforts to create a user-friendly an
235250

236251
- Supports proxy connection
237252

238-

sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from urllib3.util.retry import Retry
3232
from azure.core.paging import ItemPaged # type: ignore
3333
from azure.core import PipelineClient # type: ignore
34+
from azure.core.exceptions import raise_with_traceback # type: ignore
3435
from azure.core.pipeline.policies import ( # type: ignore
3536
HTTPPolicy,
3637
ContentDecodePolicy,
@@ -2480,11 +2481,14 @@ def __CheckAndUnifyQueryFormat(self, query_body):
24802481
def __ValidateResource(resource):
24812482
id_ = resource.get("id")
24822483
if id_:
2483-
if id_.find("/") != -1 or id_.find("\\") != -1 or id_.find("?") != -1 or id_.find("#") != -1:
2484-
raise ValueError("Id contains illegal chars.")
2485-
2486-
if id_[-1] == " ":
2487-
raise ValueError("Id ends with a space.")
2484+
try:
2485+
if id_.find("/") != -1 or id_.find("\\") != -1 or id_.find("?") != -1 or id_.find("#") != -1:
2486+
raise ValueError("Id contains illegal chars.")
2487+
2488+
if id_[-1] == " ":
2489+
raise ValueError("Id ends with a space.")
2490+
except AttributeError:
2491+
raise_with_traceback(TypeError, message="Id type must be a string.")
24882492

24892493
# Adds the partition key to options
24902494
def _AddPartitionKey(self, collection_link, document, options):

sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/base_execution_context.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __iter__(self):
8181
"""Returns itself as an iterator"""
8282
return self
8383

84-
def next(self):
84+
def __next__(self):
8585
"""Return the next query result.
8686
8787
:return: The next query result.
@@ -101,10 +101,6 @@ def next(self):
101101

102102
return self._buffer.popleft()
103103

104-
def __next__(self):
105-
# supports python 3 iterator
106-
return self.next()
107-
108104
def _fetch_items_helper_no_retries(self, fetch_function):
109105
"""Fetches more items and doesn't retry on failure
110106
@@ -138,6 +134,8 @@ def callback():
138134

139135
return _retry_utility.Execute(self._client, self._client._global_endpoint_manager, callback)
140136

137+
next = __next__ # Python 2 compatibility.
138+
141139

142140
class _DefaultQueryExecutionContext(_QueryExecutionContextBase):
143141
"""

sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/document_producer.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,13 @@ def fetch_fn(options):
6464

6565
self._ex_context = _DefaultQueryExecutionContext(client, self._options, fetch_fn)
6666

67-
def get_target_range(self):
68-
"""Returns the target partition key range.
69-
:return:
70-
Target partition key range.
71-
:rtype: dict
72-
"""
73-
return self._partition_key_target_range
67+
def __lt__(self, other):
68+
return self._doc_producer_comp.compare(self, other) < 0
7469

7570
def __iter__(self):
7671
return self
7772

78-
def next(self):
73+
def __next__(self):
7974
"""
8075
:return: The next result item.
8176
:rtype: dict
@@ -89,9 +84,13 @@ def next(self):
8984

9085
return next(self._ex_context)
9186

92-
def __next__(self):
93-
# supports python 3 iterator
94-
return self.next()
87+
def get_target_range(self):
88+
"""Returns the target partition key range.
89+
:return:
90+
Target partition key range.
91+
:rtype: dict
92+
"""
93+
return self._partition_key_target_range
9594

9695
def peek(self):
9796
"""
@@ -106,8 +105,7 @@ def peek(self):
106105

107106
return self._cur_item
108107

109-
def __lt__(self, other):
110-
return self._doc_producer_comp.compare(self, other) < 0
108+
next = __next__ # Python 2 compatibility.
111109

112110

113111
def _compare_helper(a, b):

sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/endpoint_component.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ def __init__(self, execution_context):
4444
def __iter__(self):
4545
return self
4646

47-
def next(self):
48-
return next(self._execution_context)
49-
5047
def __next__(self):
5148
# supports python 3 iterator
52-
return self.next()
49+
return next(self._execution_context)
50+
51+
next = __next__ # Python 2 compatibility.
5352

5453

5554
class _QueryExecutionOrderByEndpointComponent(_QueryExecutionEndpointComponent):
5655
"""Represents an endpoint in handling an order by query.
5756
5857
For each processed orderby result it returns 'payload' item of the result.
5958
"""
60-
61-
def next(self):
59+
def __next__(self):
6260
return next(self._execution_context)["payload"]
6361

62+
next = __next__ # Python 2 compatibility.
63+
6464

6565
class _QueryExecutionTopEndpointComponent(_QueryExecutionEndpointComponent):
6666
"""Represents an endpoint in handling top query.
@@ -72,13 +72,15 @@ def __init__(self, execution_context, top_count):
7272
super(_QueryExecutionTopEndpointComponent, self).__init__(execution_context)
7373
self._top_count = top_count
7474

75-
def next(self):
75+
def __next__(self):
7676
if self._top_count > 0:
7777
res = next(self._execution_context)
7878
self._top_count -= 1
7979
return res
8080
raise StopIteration
8181

82+
next = __next__ # Python 2 compatibility.
83+
8284

8385
class _QueryExecutionDistinctOrderedEndpointComponent(_QueryExecutionEndpointComponent):
8486
"""Represents an endpoint in handling distinct query.
@@ -89,13 +91,15 @@ def __init__(self, execution_context):
8991
super(_QueryExecutionDistinctOrderedEndpointComponent, self).__init__(execution_context)
9092
self.last_result = None
9193

92-
def next(self):
94+
def __next__(self):
9395
res = next(self._execution_context)
9496
while self.last_result == res:
9597
res = next(self._execution_context)
9698
self.last_result = res
9799
return res
98100

101+
next = __next__ # Python 2 compatibility.
102+
99103

100104
class _QueryExecutionDistinctUnorderedEndpointComponent(_QueryExecutionEndpointComponent):
101105
"""Represents an endpoint in handling distinct query.
@@ -119,14 +123,14 @@ def make_hash(self, value):
119123

120124
return tuple(frozenset(sorted(new_value.items())))
121125

122-
def next(self):
126+
def __next__(self):
123127
res = next(self._execution_context)
124128

125129
json_repr = json.dumps(self.make_hash(res))
126130
if six.PY3:
127131
json_repr = json_repr.encode("utf-8")
128132

129-
hash_object = hashlib.sha1(json_repr)
133+
hash_object = hashlib.sha1(json_repr) # nosec
130134
hashed_result = hash_object.hexdigest()
131135

132136
while hashed_result in self.last_result:
@@ -135,11 +139,13 @@ def next(self):
135139
if six.PY3:
136140
json_repr = json_repr.encode("utf-8")
137141

138-
hash_object = hashlib.sha1(json_repr)
142+
hash_object = hashlib.sha1(json_repr) # nosec
139143
hashed_result = hash_object.hexdigest()
140144
self.last_result.add(hashed_result)
141145
return res
142146

147+
next = __next__ # Python 2 compatibility.
148+
143149

144150
class _QueryExecutionOffsetEndpointComponent(_QueryExecutionEndpointComponent):
145151
"""Represents an endpoint in handling offset query.
@@ -150,7 +156,7 @@ def __init__(self, execution_context, offset_count):
150156
super(_QueryExecutionOffsetEndpointComponent, self).__init__(execution_context)
151157
self._offset_count = offset_count
152158

153-
def next(self):
159+
def __next__(self):
154160
while self._offset_count > 0:
155161
res = next(self._execution_context)
156162
if res is not None:
@@ -159,6 +165,8 @@ def next(self):
159165
raise StopIteration
160166
return next(self._execution_context)
161167

168+
next = __next__ # Python 2 compatibility.
169+
162170

163171
class _QueryExecutionAggregateEndpointComponent(_QueryExecutionEndpointComponent):
164172
"""Represents an endpoint in handling aggregate query.
@@ -183,7 +191,7 @@ def __init__(self, execution_context, aggregate_operators):
183191
elif operator == "Sum":
184192
self._local_aggregators.append(_SumAggregator())
185193

186-
def next(self):
194+
def __next__(self):
187195
for res in self._execution_context:
188196
for item in res:
189197
for operator in self._local_aggregators:
@@ -200,3 +208,5 @@ def next(self):
200208
self._result_index += 1
201209
return res
202210
raise StopIteration
211+
212+
next = __next__ # Python 2 compatibility.

sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/execution_dispatcher.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, client, resource_link, query, options, fetch_function):
6868
self._query = query
6969
self._fetch_function = fetch_function
7070

71-
def next(self):
71+
def __next__(self):
7272
"""Returns the next query result.
7373
7474
:return: The next query result.
@@ -128,6 +128,9 @@ def _create_pipelined_execution_context(self, query_execution_info):
128128
return _PipelineExecutionContext(self._client, self._options, execution_context_aggregator,
129129
query_execution_info)
130130

131+
next = __next__ # Python 2 compatibility.
132+
133+
131134
class _PipelineExecutionContext(_QueryExecutionContextBase): # pylint: disable=abstract-method
132135

133136
DEFAULT_PAGE_SIZE = 1000
@@ -171,7 +174,7 @@ def __init__(self, client, options, execution_context, query_execution_info):
171174
else:
172175
self._endpoint = endpoint_component._QueryExecutionDistinctUnorderedEndpointComponent(self._endpoint)
173176

174-
def next(self):
177+
def __next__(self):
175178
"""Returns the next query result.
176179
177180
:return: The next query result.
@@ -201,3 +204,5 @@ def fetch_next_block(self):
201204
# no more results
202205
break
203206
return results
207+
208+
next = __next__ # Python 2 compatibility.

sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/multi_execution_aggregator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self, client, resource_link, query, options, partitioned_query_ex_i
102102
except StopIteration:
103103
continue
104104

105-
def next(self):
105+
def __next__(self):
106106
"""Returns the next result
107107
108108
:return: The next result.
@@ -157,3 +157,5 @@ def _get_target_parition_key_range(self):
157157
return self._routing_provider.get_overlapping_ranges(
158158
self._resource_link, [routing_range.Range.ParseFromDict(range_as_dict) for range_as_dict in query_ranges]
159159
)
160+
161+
next = __next__ # Python 2 compatibility.

sdk/cosmos/azure-cosmos/azure/cosmos/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22-
VERSION = "4.0.0"
22+
VERSION = "4.0.1"

sdk/cosmos/azure-cosmos/azure/cosmos/container.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def query_items_change_feed(
282282
def query_items(
283283
self,
284284
query, # type: str
285-
parameters=None, # type: Optional[List[str]]
285+
parameters=None, # type: Optional[List[Dict[str, object]]]
286286
partition_key=None, # type: Optional[Any]
287287
enable_cross_partition_query=None, # type: Optional[bool]
288288
max_item_count=None, # type: Optional[int]
@@ -299,7 +299,9 @@ def query_items(
299299
the WHERE clause.
300300
301301
:param query: The Azure Cosmos DB SQL query to execute.
302-
:param parameters: Optional array of parameters to the query. Ignored if no query is provided.
302+
:param parameters: Optional array of parameters to the query.
303+
Each parameter is a dict() with 'name' and 'value' keys.
304+
Ignored if no query is provided.
303305
:param partition_key: Specifies the partition key value for the item.
304306
:param enable_cross_partition_query: Allows sending of more than one request to
305307
execute the query in the Azure Cosmos DB service.
@@ -449,7 +451,11 @@ def upsert_item(
449451
request_options["postTriggerInclude"] = post_trigger_include
450452

451453
result = self.client_connection.UpsertItem(
452-
database_or_container_link=self.container_link, document=body, **kwargs)
454+
database_or_container_link=self.container_link,
455+
document=body,
456+
options=request_options,
457+
**kwargs
458+
)
453459
if response_hook:
454460
response_hook(self.client_connection.last_response_headers, result)
455461
return result

sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"""Create, read, and delete databases in the Azure Cosmos DB SQL API service.
2323
"""
2424

25-
from typing import Any, Dict, Mapping, Optional, Union, cast, Iterable, List # pylint: disable=unused-import
25+
from typing import Any, Dict, Optional, Union, cast, Iterable, List # pylint: disable=unused-import
2626

2727
import six
2828
from azure.core.tracing.decorator import distributed_trace # type: ignore
@@ -320,10 +320,11 @@ def get_database_client(self, database):
320320
"""
321321
if isinstance(database, DatabaseProxy):
322322
id_value = database.id
323-
elif isinstance(database, Mapping):
324-
id_value = database["id"]
325323
else:
326-
id_value = database
324+
try:
325+
id_value = database["id"]
326+
except TypeError:
327+
id_value = database
327328

328329
return DatabaseProxy(self.client_connection, id_value)
329330

0 commit comments

Comments
 (0)