Skip to content

Commit 6bd2131

Browse files
committed
fix: merging query_items with feed_range and continuation bug fix manually
1 parent 7f0cb4a commit 6bd2131

14 files changed

+212
-17
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
## Release History
22

3+
### 4.14.1 (Unreleased)
4+
5+
#### Features Added
6+
7+
#### Breaking Changes
8+
9+
#### Bugs Fixed
10+
* Fixed bug where queries using `feed_range` and `continuation` options would not work as expected. See [PR 43700](https://github.com/Azure/azure-sdk-for-python/pull/43700).
11+
12+
#### Other Changes
13+
314
### 4.14.0 (2025-10-13)
415
This version and all future versions will require Python 3.9+.
516

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,3 +941,17 @@ def _build_properties_cache(properties: dict[str, Any], container_link: str) ->
941941
"_self": properties.get("_self", None), "_rid": properties.get("_rid", None),
942942
"partitionKey": properties.get("partitionKey", None), "container_link": container_link
943943
}
944+
945+
def format_pk_range_options(query_options: Mapping[str, Any]) -> dict[str, Any]:
946+
"""Formats the partition key range options to be used internally from the query ones.
947+
:param dict query_options: The query options being used.
948+
:return: The relevant partition key range options.
949+
:rtype: dict
950+
"""
951+
pk_range_options: dict[str, Any] = {}
952+
if query_options is not None:
953+
if "containerRID" in query_options:
954+
pk_range_options["containerRID"] = query_options["containerRID"]
955+
if "excludedLocations" in query_options:
956+
pk_range_options["excludedLocations"] = query_options["excludedLocations"]
957+
return pk_range_options

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3259,7 +3259,6 @@ def __GetBodiesFromQueryResult(result: dict[str, Any]) -> list[dict[str, Any]]:
32593259

32603260
# If feed_range_epk exist, query with the range
32613261
if feed_range_epk is not None:
3262-
last_response_headers = CaseInsensitiveDict()
32633262
over_lapping_ranges = self._routing_map_provider.get_overlapping_ranges(resource_id, [feed_range_epk],
32643263
options)
32653264
# It is possible to get more than one over lapping range. We need to get the query results for each one

sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/hybrid_search_aggregator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
"""Internal class for multi execution context aggregator implementation in the Azure Cosmos database service.
55
"""
6-
76
from azure.cosmos._execution_context.aio.base_execution_context import _QueryExecutionContextBase
87
from azure.cosmos._execution_context.aio import document_producer
98
from azure.cosmos._execution_context.hybrid_search_aggregator import _retrieve_component_scores, _rewrite_query_infos, \

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
"""Internal class for multi execution context aggregator implementation in the Azure Cosmos database service.
2323
"""
24-
2524
from azure.cosmos._execution_context.aio.base_execution_context import _QueryExecutionContextBase
2625
from azure.cosmos._execution_context.aio import document_producer, _queue_async_helper
2726
from azure.cosmos._routing import routing_range
@@ -162,7 +161,6 @@ def _createTargetPartitionQueryExecutionContext(self, partition_key_target_range
162161
)
163162

164163
async def _get_target_partition_key_range(self):
165-
166164
query_ranges = self._partitioned_query_ex_info.get_query_ranges()
167165
return await self._routing_provider.get_overlapping_ranges(
168166
self._resource_link,

sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/non_streaming_order_by_aggregator.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
"""Internal class for multi execution context aggregator implementation in the Azure Cosmos database service.
55
"""
6-
76
from azure.cosmos._execution_context.aio.base_execution_context import _QueryExecutionContextBase
87
from azure.cosmos._execution_context.aio.multi_execution_aggregator import _MultiExecutionContextAggregator
98
from azure.cosmos._execution_context.aio import document_producer
@@ -107,7 +106,6 @@ def _createTargetPartitionQueryExecutionContext(self, partition_key_target_range
107106
)
108107

109108
async def _get_target_partition_key_range(self):
110-
111109
query_ranges = self._partitioned_query_ex_info.get_query_ranges()
112110
return await self._routing_provider.get_overlapping_ranges(
113111
self._resource_link,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def _createTargetPartitionQueryExecutionContext(self, partition_key_target_range
195195
)
196196

197197
def _get_target_partition_key_range(self):
198-
199198
query_ranges = self._partitioned_query_ex_info.get_query_ranges()
200199
return self._routing_provider.get_overlapping_ranges(
201200
self._resource_link,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
"""Internal class for multi execution context aggregator implementation in the Azure Cosmos database service.
55
"""
6-
76
from azure.cosmos._execution_context.base_execution_context import _QueryExecutionContextBase
87
from azure.cosmos._execution_context.multi_execution_aggregator import _MultiExecutionContextAggregator
98
from azure.cosmos._execution_context import document_producer

sdk/cosmos/azure-cosmos/azure/cosmos/_routing/aio/routing_map_provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ async def get_overlapping_ranges(self, collection_link, partition_key_ranges, fe
6161
:rtype: list
6262
"""
6363
collection_id = _base.GetResourceIdOrFullNameFromLink(collection_link)
64-
await self.init_collection_routing_map_if_needed(collection_link, collection_id, feed_options, **kwargs)
64+
pk_range_options = _base.format_pk_range_options(feed_options)
65+
await self.init_collection_routing_map_if_needed(collection_link, collection_id, pk_range_options, **kwargs)
6566

6667
return self._collection_routing_map_by_item[collection_id].get_overlapping_ranges(partition_key_ranges)
6768

@@ -95,7 +96,8 @@ async def get_range_by_partition_key_range_id(
9596
**kwargs: dict[str, Any]
9697
) -> Optional[dict[str, Any]]:
9798
collection_id = _base.GetResourceIdOrFullNameFromLink(collection_link)
98-
await self.init_collection_routing_map_if_needed(collection_link, collection_id, feed_options, **kwargs)
99+
pk_range_options = _base.format_pk_range_options(feed_options)
100+
await self.init_collection_routing_map_if_needed(collection_link, collection_id, pk_range_options, **kwargs)
99101

100102
return self._collection_routing_map_by_item[collection_id].get_range_by_partition_key_range_id(
101103
partition_key_range_id)

sdk/cosmos/azure-cosmos/azure/cosmos/_routing/routing_map_provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def get_overlapping_ranges(self, collection_link, partition_key_ranges, feed_opt
8484
:rtype: list
8585
"""
8686
collection_id = _base.GetResourceIdOrFullNameFromLink(collection_link)
87-
self.init_collection_routing_map_if_needed(collection_link, collection_id, feed_options, **kwargs)
87+
pk_range_options = _base.format_pk_range_options(feed_options)
88+
self.init_collection_routing_map_if_needed(collection_link, collection_id, pk_range_options, **kwargs)
8889

8990
return self._collection_routing_map_by_item[collection_id].get_overlapping_ranges(partition_key_ranges)
9091

@@ -96,7 +97,8 @@ def get_range_by_partition_key_range_id(
9697
**kwargs: dict[str, Any]
9798
) -> Optional[dict[str, Any]]:
9899
collection_id = _base.GetResourceIdOrFullNameFromLink(collection_link)
99-
self.init_collection_routing_map_if_needed(collection_link, collection_id, feed_options, **kwargs)
100+
pk_range_options = _base.format_pk_range_options(feed_options)
101+
self.init_collection_routing_map_if_needed(collection_link, collection_id, pk_range_options, **kwargs)
100102

101103
return (self._collection_routing_map_by_item[collection_id]
102104
.get_range_by_partition_key_range_id(partition_key_range_id))

0 commit comments

Comments
 (0)