Skip to content

Commit 3e2dc96

Browse files
committed
fix the model to component factory to reference the QueryProperties model type instead of generic object
1 parent 68b4118 commit 3e2dc96

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,11 +2194,20 @@ def create_http_requester(
21942194

21952195
api_budget = self._api_budget
21962196

2197+
# Removes QueryProperties components from the interpolated mappings because it has been designed
2198+
# to be used by the SimpleRetriever and will be resolved from the provider from the slice directly
2199+
# instead of through jinja interpolation
2200+
request_parameters: Optional[Union[str, Mapping[str, str]]]
2201+
if isinstance(model.request_parameters, Mapping):
2202+
request_parameters = self._remove_query_properties(model.request_parameters)
2203+
else:
2204+
request_parameters = model.request_parameters
2205+
21972206
request_options_provider = InterpolatedRequestOptionsProvider(
21982207
request_body_data=model.request_body_data,
21992208
request_body_json=model.request_body_json,
22002209
request_headers=model.request_headers,
2201-
request_parameters=model.request_parameters,
2210+
request_parameters=request_parameters,
22022211
query_properties_key=query_properties_key,
22032212
config=config,
22042213
parameters=model.parameters or {},
@@ -2946,34 +2955,18 @@ def create_simple_retriever(
29462955
# When translating JSON schema into Pydantic models, enforcing types for arrays containing both
29472956
# concrete string complex object definitions like QueryProperties would get resolved to Union[str, Any].
29482957
# This adds the extra validation that we couldn't get for free in Pydantic model generation
2949-
if (
2950-
isinstance(request_parameter, Mapping)
2951-
and request_parameter.get("type") == "QueryProperties"
2952-
):
2958+
if isinstance(request_parameter, QueryPropertiesModel):
29532959
query_properties_key = key
29542960
query_properties_definitions.append(request_parameter)
2955-
elif not isinstance(request_parameter, str):
2956-
raise ValueError(
2957-
f"Each element of request_parameters should be of type str or QueryProperties, but received {request_parameter.get('type')}"
2958-
)
29592961

29602962
if len(query_properties_definitions) > 1:
29612963
raise ValueError(
29622964
f"request_parameters only supports defining one QueryProperties field, but found {len(query_properties_definitions)} usages"
29632965
)
29642966

29652967
if len(query_properties_definitions) == 1:
2966-
query_properties = self.create_component(
2967-
model_type=QueryPropertiesModel,
2968-
component_definition=query_properties_definitions[0],
2969-
config=config,
2970-
)
2971-
2972-
# Removes QueryProperties components from the interpolated mappings because it will be resolved in
2973-
# the provider from the slice directly instead of through jinja interpolation
2974-
if isinstance(model.requester.request_parameters, Mapping):
2975-
model.requester.request_parameters = self._remove_query_properties(
2976-
model.requester.request_parameters
2968+
query_properties = self._create_component_from_model(
2969+
model=query_properties_definitions[0], config=config
29772970
)
29782971

29792972
requester = self._create_component_from_model(
@@ -3096,13 +3089,12 @@ def create_simple_retriever(
30963089

30973090
@staticmethod
30983091
def _remove_query_properties(
3099-
request_parameters: Mapping[str, Union[Any, str]],
3100-
) -> Mapping[str, Union[Any, str]]:
3092+
request_parameters: Mapping[str, Union[str, QueryPropertiesModel]],
3093+
) -> Mapping[str, str]:
31013094
return {
31023095
parameter_field: request_parameter
31033096
for parameter_field, request_parameter in request_parameters.items()
3104-
if not isinstance(request_parameter, Mapping)
3105-
or not request_parameter.get("type") == "QueryProperties"
3097+
if not isinstance(request_parameter, QueryPropertiesModel)
31063098
}
31073099

31083100
def create_state_delegating_stream(

0 commit comments

Comments
 (0)