66import copy
77from typing import Any , Dict , List , Mapping , Optional , Union
88
9- from airbyte_cdk .sources .declarative .requesters .request_option import RequestOption , RequestOptionType
9+ from airbyte_cdk .sources .declarative .requesters .request_option import (
10+ RequestOption ,
11+ RequestOptionType ,
12+ )
1013from airbyte_cdk .sources .types import Config
1114
15+
1216def _merge_mappings (
1317 target : Dict [str , Any ],
1418 source : Mapping [str , Any ],
@@ -35,13 +39,17 @@ def _merge_mappings(
3539 if isinstance (target_value , dict ) and isinstance (source_value , dict ):
3640 # Only body_json supports nested_structures
3741 if not allow_same_value_merge :
38- raise ValueError (f"Request body collision, duplicate keys detected at: { '.' .join (current_path )} . Please ensure that all keys in request are unique." )
42+ raise ValueError (
43+ f"Request body collision, duplicate keys detected at key path: { '.' .join (current_path )} . Please ensure that all keys in the request are unique."
44+ )
3945 # If both are dictionaries, recursively merge them
4046 _merge_mappings (target_value , source_value , current_path , allow_same_value_merge )
4147
4248 elif not allow_same_value_merge or target_value != source_value :
4349 # If same key has different values, that's a conflict
44- raise ValueError (f"Request body collision, duplicate keys detected at: { '.' .join (current_path )} . Please ensure that all keys in request are unique." )
50+ raise ValueError (
51+ f"Request body collision, duplicate keys detected at key path: { '.' .join (current_path )} . Please ensure that all keys in the request are unique."
52+ )
4553 else :
4654 # No conflict, just copy the value (using deepcopy for nested structures)
4755 target [key ] = copy .deepcopy (source_value )
@@ -105,9 +113,9 @@ def combine_mappings(
105113
106114 return result
107115
108- def _validate_multiple_request_options (
109- config : Config ,
110- * request_options : Optional [RequestOption ]
116+
117+ def _validate_component_request_option_paths (
118+ config : Config , * request_options : Optional [RequestOption ]
111119) -> None :
112120 """
113121 Validates that a component with multiple request options does not have conflicting paths.
@@ -117,24 +125,21 @@ def _validate_multiple_request_options(
117125 for option in request_options :
118126 if option :
119127 grouped_options .setdefault (option .inject_into , []).append (option )
120-
128+
121129 for inject_type , options in grouped_options .items ():
122130 if len (options ) <= 1 :
123131 continue
124-
132+
125133 option_dicts : List [Optional [Union [Mapping [str , Any ], str ]]] = []
126134 for i , option in enumerate (options ):
127135 option_dict : Dict [str , Any ] = {}
128136 # Use indexed dummy values to ensure we catch conflicts
129137 option .inject_into_request (option_dict , f"dummy_value_{ i } " , config )
130138 option_dicts .append (option_dict )
131-
139+
132140 try :
133141 combine_mappings (
134- option_dicts ,
135- allow_same_value_merge = (inject_type == RequestOptionType .body_json )
142+ option_dicts , allow_same_value_merge = (inject_type == RequestOptionType .body_json )
136143 )
137- except ValueError as e :
138- print (e )
139- raise ValueError (f"Conflict mapping request options: { e } " ) from e
140-
144+ except ValueError as error :
145+ raise ValueError (error )
0 commit comments