@@ -104,9 +104,7 @@ def merge_schemas(schema1: SchemaType, schema2: SchemaType) -> SchemaType:
104
104
t1 = merged_schema .get (k2 )
105
105
if t1 is None :
106
106
merged_schema [k2 ] = t2
107
- # do not pass fields with null values to the _choose_wider_type method if their keys are already
108
- # in the merged schema due to issue observed in https://github.com/airbytehq/oncall/issues/4948
109
- elif t1 == t2 or t2 ["type" ] == "null" :
107
+ elif t1 == t2 :
110
108
continue
111
109
else :
112
110
merged_schema [k2 ] = _choose_wider_type (k2 , t1 , t2 )
@@ -119,23 +117,27 @@ def _is_valid_type(t: JsonSchemaSupportedType) -> bool:
119
117
120
118
121
119
def _choose_wider_type (key : str , t1 : Mapping [str , Any ], t2 : Mapping [str , Any ]) -> Mapping [str , Any ]:
122
- if (t1 ["type" ] == "array" or t2 ["type" ] == "array" ) and t1 != t2 :
120
+ t1_type = t1 ["type" ]
121
+ t2_type = t2 ["type" ]
122
+
123
+ if (t1_type == "array" or t2_type == "array" ) and t1 != t2 :
123
124
raise SchemaInferenceError (
124
125
FileBasedSourceError .SCHEMA_INFERENCE_ERROR ,
125
126
details = "Cannot merge schema for unequal array types." ,
126
127
key = key ,
127
128
detected_types = f"{ t1 } ,{ t2 } " ,
128
129
)
129
- elif (t1 ["type" ] == "object" or t2 ["type" ] == "object" ) and t1 != t2 :
130
+ # Schemas can still be merged if a key contains a null value in either t1 or t2, but it is still an object
131
+ elif (t1_type == "object" or t2_type == "object" ) and t1_type != "null" and t2_type != "null" and t1 != t2 :
130
132
raise SchemaInferenceError (
131
133
FileBasedSourceError .SCHEMA_INFERENCE_ERROR ,
132
134
details = "Cannot merge schema for unequal object types." ,
133
135
key = key ,
134
136
detected_types = f"{ t1 } ,{ t2 } " ,
135
137
)
136
138
else :
137
- comparable_t1 = get_comparable_type (TYPE_PYTHON_MAPPING [t1 [ "type" ] ][0 ]) # accessing the type_mapping value
138
- comparable_t2 = get_comparable_type (TYPE_PYTHON_MAPPING [t2 [ "type" ] ][0 ]) # accessing the type_mapping value
139
+ comparable_t1 = get_comparable_type (TYPE_PYTHON_MAPPING [t1_type ][0 ]) # accessing the type_mapping value
140
+ comparable_t2 = get_comparable_type (TYPE_PYTHON_MAPPING [t2_type ][0 ]) # accessing the type_mapping value
139
141
if not comparable_t1 and comparable_t2 :
140
142
raise SchemaInferenceError (FileBasedSourceError .UNRECOGNIZED_TYPE , key = key , detected_types = f"{ t1 } ,{ t2 } " )
141
143
return max (
0 commit comments