|
31 | 31 | from typing import Dict, Any, List, Mapping, Optional, Sequence, Union, Tuple, TYPE_CHECKING
|
32 | 32 |
|
33 | 33 | from urllib.parse import quote as urllib_quote
|
| 34 | +from urllib.parse import unquote as urllib_unquote |
34 | 35 | from urllib.parse import urlsplit
|
35 | 36 | from azure.core import MatchConditions
|
36 | 37 |
|
@@ -358,6 +359,8 @@ def set_session_token_header(
|
358 | 359 | # then update from session container
|
359 | 360 | if headers[http_constants.HttpHeaders.ConsistencyLevel] == documents.ConsistencyLevel.Session and \
|
360 | 361 | cosmos_client_connection.session:
|
| 362 | + # urllib_unquote is used to decode the path, as it may contain encoded characters |
| 363 | + path = urllib_unquote(path) |
361 | 364 | # populate session token from the client's session container
|
362 | 365 | session_token = (
|
363 | 366 | cosmos_client_connection.session.get_session_token(path,
|
@@ -387,6 +390,8 @@ async def set_session_token_header_async(
|
387 | 390 | if headers[http_constants.HttpHeaders.ConsistencyLevel] == documents.ConsistencyLevel.Session and \
|
388 | 391 | cosmos_client_connection.session:
|
389 | 392 | # populate session token from the client's session container
|
| 393 | + # urllib_unquote is used to decode the path, as it may contain encoded characters |
| 394 | + path = urllib_unquote(path) |
390 | 395 | session_token = \
|
391 | 396 | await cosmos_client_connection.session.get_session_token_async(path,
|
392 | 397 | options.get('partitionKey'),
|
@@ -608,19 +613,21 @@ def GetItemContainerInfo(self_link: str, alt_content_path: str, resource_id: str
|
608 | 613 |
|
609 | 614 | self_link = TrimBeginningAndEndingSlashes(self_link) + "/"
|
610 | 615 |
|
611 |
| - index = IndexOfNth(self_link, "/", 4) |
| 616 | + end_index = IndexOfNth(self_link, "/", 4) |
| 617 | + start_index = IndexOfNth(self_link, "/", 3) |
612 | 618 |
|
613 |
| - if index != -1: |
614 |
| - collection_id = self_link[0:index] |
| 619 | + if start_index != -1 and end_index != -1: |
| 620 | + # parse only the collection rid from the path as it's unique across databases |
| 621 | + collection_rid = self_link[start_index + 1:end_index] |
615 | 622 |
|
616 | 623 | if "colls" in self_link:
|
617 | 624 | # this is a collection request
|
618 | 625 | index_second_slash = IndexOfNth(alt_content_path, "/", 2)
|
619 | 626 | if index_second_slash == -1:
|
620 | 627 | collection_name = alt_content_path + "/colls/" + urllib_quote(resource_id)
|
621 |
| - return collection_id, collection_name |
| 628 | + return collection_rid, collection_name |
622 | 629 | collection_name = alt_content_path
|
623 |
| - return collection_id, collection_name |
| 630 | + return collection_rid, collection_name |
624 | 631 | raise ValueError(
|
625 | 632 | "Response Not from Server Partition, self_link: {0}, alt_content_path: {1}, id: {2}".format(
|
626 | 633 | self_link, alt_content_path, resource_id
|
|
0 commit comments