@@ -144,6 +144,13 @@ impl PartitionKeyRangeCache {
144144 )
145145 . await ;
146146
147+ if let Err ( ref e) = routing_map {
148+ tracing:: warn!(
149+ collection_rid,
150+ error = %e,
151+ "Failed to fetch routing map for collection"
152+ ) ;
153+ }
147154 Ok ( routing_map. ok ( ) )
148155 }
149156
@@ -189,7 +196,7 @@ impl PartitionKeyRangeCache {
189196 let pk_range_link = self
190197 . database_link
191198 . feed ( ResourceType :: Containers )
192- . item ( collection_rid)
199+ . item_by_rid ( collection_rid)
193200 . feed ( ResourceType :: PartitionKeyRanges ) ;
194201 let response = self
195202 . execute_partition_key_range_read_change_feed (
@@ -673,4 +680,61 @@ mod tests {
673680 assert ! ( range. target_throughput. is_some( ) ) ;
674681 assert_eq ! ( range. target_throughput. unwrap( ) , 1000.0 ) ;
675682 }
683+
684+ // Tests verifying that the pkranges resource link uses item_by_rid() so that
685+ // collection RIDs (which are base64-encoded and can contain '=', '+', '/') are
686+ // not URL-percent-encoded. Using item() would encode '=' to '%3D', causing 404s.
687+
688+ #[ test]
689+ fn pkranges_link_rid_with_equals_is_not_encoded ( ) {
690+ // RIDs like "pLLZAIuPigw=" contain '=' which item() would encode to '%3D'.
691+ // item_by_rid() must preserve it as-is.
692+ let collection_rid = "pLLZAIuPigw=" ;
693+ let database_link = ResourceLink :: root ( ResourceType :: Databases ) . item ( "perfdb" ) ;
694+ let pk_range_link = database_link
695+ . feed ( ResourceType :: Containers )
696+ . item_by_rid ( collection_rid)
697+ . feed ( ResourceType :: PartitionKeyRanges ) ;
698+
699+ // Correct: '=' preserved, not encoded to '%3D'
700+ assert_eq ! (
701+ "dbs/perfdb/colls/pLLZAIuPigw=/pkranges" ,
702+ pk_range_link. path( )
703+ ) ;
704+ }
705+
706+ #[ test]
707+ fn pkranges_link_item_encodes_equals_incorrectly ( ) {
708+ // Demonstrates the bug: item() URL-encodes '=' to '%3D', producing a path
709+ // that Cosmos DB cannot find (404).
710+ let collection_rid = "pLLZAIuPigw=" ;
711+ let database_link = ResourceLink :: root ( ResourceType :: Databases ) . item ( "perfdb" ) ;
712+ let pk_range_link_wrong = database_link
713+ . feed ( ResourceType :: Containers )
714+ . item ( collection_rid)
715+ . feed ( ResourceType :: PartitionKeyRanges ) ;
716+
717+ // Wrong: '=' is encoded to '%3D', causing 404 from Cosmos DB
718+ assert ! (
719+ pk_range_link_wrong. path( ) . contains( "%3D" ) ,
720+ "item() should URL-encode '=' to '%3D'"
721+ ) ;
722+ assert_eq ! (
723+ "dbs/perfdb/colls/pLLZAIuPigw%3D/pkranges" ,
724+ pk_range_link_wrong. path( )
725+ ) ;
726+ }
727+
728+ #[ test]
729+ fn pkranges_link_rid_with_plus_is_not_encoded ( ) {
730+ // RIDs may also contain '+' (base64 char). item_by_rid() must preserve it.
731+ let collection_rid = "AB+CD/EF==" ;
732+ let database_link = ResourceLink :: root ( ResourceType :: Databases ) . item ( "mydb" ) ;
733+ let pk_range_link = database_link
734+ . feed ( ResourceType :: Containers )
735+ . item_by_rid ( collection_rid)
736+ . feed ( ResourceType :: PartitionKeyRanges ) ;
737+
738+ assert_eq ! ( "dbs/mydb/colls/AB+CD/EF==/pkranges" , pk_range_link. path( ) ) ;
739+ }
676740}
0 commit comments