Skip to content

Commit dae0b98

Browse files
author
octavia-squidington-iii
committed
Auto-fix lint and format issues
1 parent 604dbe8 commit dae0b98

File tree

4 files changed

+105
-71
lines changed

4 files changed

+105
-71
lines changed

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

+28-52
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,7 @@ class OAuthAuthenticator(BaseModel):
609609
scopes: Optional[List[str]] = Field(
610610
None,
611611
description="List of scopes that should be granted to the access token.",
612-
examples=[
613-
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
614-
],
612+
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
615613
title="Scopes",
616614
)
617615
token_expiry_date: Optional[str] = Field(
@@ -1080,28 +1078,24 @@ class OAuthConfigSpecification(BaseModel):
10801078
class Config:
10811079
extra = Extra.allow
10821080

1083-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1084-
Field(
1085-
None,
1086-
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1087-
examples=[
1088-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1089-
{
1090-
"app_id": {
1091-
"type": "string",
1092-
"path_in_connector_config": ["info", "app_id"],
1093-
}
1094-
},
1095-
],
1096-
title="OAuth user input",
1097-
)
1081+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1082+
None,
1083+
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1084+
examples=[
1085+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1086+
{
1087+
"app_id": {
1088+
"type": "string",
1089+
"path_in_connector_config": ["info", "app_id"],
1090+
}
1091+
},
1092+
],
1093+
title="OAuth user input",
10981094
)
1099-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1100-
Field(
1101-
None,
1102-
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1103-
title="DeclarativeOAuth Connector Specification",
1104-
)
1095+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1096+
None,
1097+
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1098+
title="DeclarativeOAuth Connector Specification",
11051099
)
11061100
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
11071101
None,
@@ -1119,9 +1113,7 @@ class Config:
11191113
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
11201114
None,
11211115
description="OAuth specific blob. This is a Json Schema used to validate Json configurations persisted as Airbyte Server configurations.\nMust be a valid non-nested JSON describing additional fields configured by the Airbyte Instance or Workspace Admins to be used by the\nserver when completing an OAuth flow (typically exchanging an auth code for refresh token).\nExamples:\n complete_oauth_server_input_specification={\n client_id: {\n type: string\n },\n client_secret: {\n type: string\n }\n }",
1122-
examples=[
1123-
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1124-
],
1116+
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
11251117
title="OAuth input specification",
11261118
)
11271119
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1774,9 +1766,7 @@ class RecordSelector(BaseModel):
17741766
description="Responsible for filtering records to be emitted by the Source.",
17751767
title="Record Filter",
17761768
)
1777-
schema_normalization: Optional[
1778-
Union[SchemaNormalization, CustomSchemaNormalization]
1779-
] = Field(
1769+
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
17801770
SchemaNormalization.None_,
17811771
description="Responsible for normalization according to the schema.",
17821772
title="Schema Normalization",
@@ -1997,9 +1987,7 @@ class Config:
19971987
description="Component used to fetch data incrementally based on a time field in the data.",
19981988
title="Incremental Sync",
19991989
)
2000-
name: Optional[str] = Field(
2001-
"", description="The stream name.", example=["Users"], title="Name"
2002-
)
1990+
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
20031991
primary_key: Optional[PrimaryKey] = Field(
20041992
"", description="The primary key of the stream.", title="Primary Key"
20051993
)
@@ -2273,11 +2261,7 @@ class SimpleRetriever(BaseModel):
22732261
CustomPartitionRouter,
22742262
ListPartitionRouter,
22752263
SubstreamPartitionRouter,
2276-
List[
2277-
Union[
2278-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2279-
]
2280-
],
2264+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
22812265
]
22822266
] = Field(
22832267
[],
@@ -2321,9 +2305,7 @@ class AsyncRetriever(BaseModel):
23212305
)
23222306
download_extractor: Optional[
23232307
Union[CustomRecordExtractor, DpathExtractor, ResponseToFileExtractor]
2324-
] = Field(
2325-
None, description="Responsible for fetching the records from provided urls."
2326-
)
2308+
] = Field(None, description="Responsible for fetching the records from provided urls.")
23272309
creation_requester: Union[CustomRequester, HttpRequester] = Field(
23282310
...,
23292311
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2357,11 +2339,7 @@ class AsyncRetriever(BaseModel):
23572339
CustomPartitionRouter,
23582340
ListPartitionRouter,
23592341
SubstreamPartitionRouter,
2360-
List[
2361-
Union[
2362-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2363-
]
2364-
],
2342+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
23652343
]
23662344
] = Field(
23672345
[],
@@ -2429,12 +2407,10 @@ class DynamicDeclarativeStream(BaseModel):
24292407
stream_template: DeclarativeStream = Field(
24302408
..., description="Reference to the stream template.", title="Stream Template"
24312409
)
2432-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2433-
Field(
2434-
...,
2435-
description="Component resolve and populates stream templates with components values.",
2436-
title="Components Resolver",
2437-
)
2410+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2411+
...,
2412+
description="Component resolve and populates stream templates with components values.",
2413+
title="Components Resolver",
24382414
)
24392415

24402416

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -2648,7 +2648,11 @@ def create_simple_retriever(
26482648
stop_condition_on_cursor: bool = False,
26492649
client_side_incremental_sync: Optional[Dict[str, Any]] = None,
26502650
transformations: List[RecordTransformation],
2651-
incremental_sync: Optional[Union[IncrementingCountCursorModel, DatetimeBasedCursorModel, CustomIncrementalSyncModel]] = None,
2651+
incremental_sync: Optional[
2652+
Union[
2653+
IncrementingCountCursorModel, DatetimeBasedCursorModel, CustomIncrementalSyncModel
2654+
]
2655+
] = None,
26522656
**kwargs: Any,
26532657
) -> SimpleRetriever:
26542658
decoder = (
@@ -2707,10 +2711,21 @@ def create_simple_retriever(
27072711
model.ignore_stream_slicer_parameters_on_paginated_requests or False
27082712
)
27092713

2710-
if model.lazy_read_pointer and not bool(self._connector_state_manager.get_stream_state(name, None)):
2711-
lazy_read_pointer = [InterpolatedString.create(path, parameters=model.parameters or {}) for path in model.lazy_read_pointer]
2712-
partition_router = self._create_component_from_model(model=model.partition_router, config=config)
2713-
stream_slicer = self._create_component_from_model(model=incremental_sync, config=config) if incremental_sync else SinglePartitionRouter(parameters={})
2714+
if model.lazy_read_pointer and not bool(
2715+
self._connector_state_manager.get_stream_state(name, None)
2716+
):
2717+
lazy_read_pointer = [
2718+
InterpolatedString.create(path, parameters=model.parameters or {})
2719+
for path in model.lazy_read_pointer
2720+
]
2721+
partition_router = self._create_component_from_model(
2722+
model=model.partition_router, config=config
2723+
)
2724+
stream_slicer = (
2725+
self._create_component_from_model(model=incremental_sync, config=config)
2726+
if incremental_sync
2727+
else SinglePartitionRouter(parameters={})
2728+
)
27142729

27152730
return LazySimpleRetriever(
27162731
name=name,

airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
import copy
77
import logging
88
from dataclasses import InitVar, dataclass
9-
from typing import TYPE_CHECKING, Any, Iterable, Tuple, List, Mapping, MutableMapping, Optional, Union
9+
from typing import (
10+
TYPE_CHECKING,
11+
Any,
12+
Iterable,
13+
List,
14+
Mapping,
15+
MutableMapping,
16+
Optional,
17+
Tuple,
18+
Union,
19+
)
1020

1121
import dpath
1222

@@ -133,7 +143,9 @@ def _get_request_option(
133143
parent_config.request_option.inject_into_request(params, value, self.config)
134144
return params
135145

136-
def process_parent_record(self, parent_record: Union[AirbyteMessage, Record, Mapping], parent_stream_name: str) -> Tuple[Optional[Mapping], Optional[Mapping]]:
146+
def process_parent_record(
147+
self, parent_record: Union[AirbyteMessage, Record, Mapping], parent_stream_name: str
148+
) -> Tuple[Optional[Mapping], Optional[Mapping]]:
137149
"""
138150
Processes and extracts data from a parent record, handling different record types
139151
and ensuring only valid types proceed.
@@ -150,7 +162,7 @@ def process_parent_record(self, parent_record: Union[AirbyteMessage, Record, Map
150162
)
151163
if parent_record.type == MessageType.RECORD:
152164
return parent_record.record.data, {}
153-
return None, None # Skip invalid or non-record data
165+
return None, None # Skip invalid or non-record data
154166

155167
# Handle Record type
156168
if isinstance(parent_record, Record):
@@ -200,7 +212,9 @@ def stream_slices(self) -> Iterable[StreamSlice]:
200212
# not support either substreams or RFR, but something that needs to be considered once we do
201213
for parent_record in parent_stream.read_only_records():
202214
# Process the parent record
203-
parent_record, parent_partition = self.process_parent_record(parent_record, parent_stream.name)
215+
parent_record, parent_partition = self.process_parent_record(
216+
parent_record, parent_stream.name
217+
)
204218

205219
# Skip invalid or non-record data
206220
if parent_record is None:

0 commit comments

Comments
 (0)