6
6
import copy
7
7
from typing import Any , Dict , List , Mapping , Optional , Union
8
8
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
+ )
10
13
from airbyte_cdk .sources .types import Config
11
14
15
+
12
16
def _merge_mappings (
13
17
target : Dict [str , Any ],
14
18
source : Mapping [str , Any ],
@@ -35,13 +39,17 @@ def _merge_mappings(
35
39
if isinstance (target_value , dict ) and isinstance (source_value , dict ):
36
40
# Only body_json supports nested_structures
37
41
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
+ )
39
45
# If both are dictionaries, recursively merge them
40
46
_merge_mappings (target_value , source_value , current_path , allow_same_value_merge )
41
47
42
48
elif not allow_same_value_merge or target_value != source_value :
43
49
# 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
+ )
45
53
else :
46
54
# No conflict, just copy the value (using deepcopy for nested structures)
47
55
target [key ] = copy .deepcopy (source_value )
@@ -105,9 +113,9 @@ def combine_mappings(
105
113
106
114
return result
107
115
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 ]
111
119
) -> None :
112
120
"""
113
121
Validates that a component with multiple request options does not have conflicting paths.
@@ -117,24 +125,21 @@ def _validate_multiple_request_options(
117
125
for option in request_options :
118
126
if option :
119
127
grouped_options .setdefault (option .inject_into , []).append (option )
120
-
128
+
121
129
for inject_type , options in grouped_options .items ():
122
130
if len (options ) <= 1 :
123
131
continue
124
-
132
+
125
133
option_dicts : List [Optional [Union [Mapping [str , Any ], str ]]] = []
126
134
for i , option in enumerate (options ):
127
135
option_dict : Dict [str , Any ] = {}
128
136
# Use indexed dummy values to ensure we catch conflicts
129
137
option .inject_into_request (option_dict , f"dummy_value_{ i } " , config )
130
138
option_dicts .append (option_dict )
131
-
139
+
132
140
try :
133
141
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 )
136
143
)
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