Skip to content

Commit b278dcd

Browse files
author
octavia-squidington-iii
committed
Auto-fix lint and format issues
1 parent 2f31d73 commit b278dcd

File tree

4 files changed

+105
-74
lines changed

4 files changed

+105
-74
lines changed

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 29 additions & 55 deletions
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
)
@@ -2257,9 +2245,7 @@ class ParentStreamConfig(BaseModel):
22572245

22582246
class StateDelegatingStream(BaseModel):
22592247
type: Literal["StateDelegatingStream"]
2260-
name: str = Field(
2261-
..., description="The stream name.", example=["Users"], title="Name"
2262-
)
2248+
name: str = Field(..., description="The stream name.", example=["Users"], title="Name")
22632249
full_refresh_stream: DeclarativeStream = Field(
22642250
...,
22652251
description="Component used to coordinate how records are extracted across stream slices and request pages when the state is empty or not provided.",
@@ -2296,11 +2282,7 @@ class SimpleRetriever(BaseModel):
22962282
CustomPartitionRouter,
22972283
ListPartitionRouter,
22982284
SubstreamPartitionRouter,
2299-
List[
2300-
Union[
2301-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2302-
]
2303-
],
2285+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
23042286
]
23052287
] = Field(
23062288
[],
@@ -2344,9 +2326,7 @@ class AsyncRetriever(BaseModel):
23442326
)
23452327
download_extractor: Optional[
23462328
Union[CustomRecordExtractor, DpathExtractor, ResponseToFileExtractor]
2347-
] = Field(
2348-
None, description="Responsible for fetching the records from provided urls."
2349-
)
2329+
] = Field(None, description="Responsible for fetching the records from provided urls.")
23502330
creation_requester: Union[CustomRequester, HttpRequester] = Field(
23512331
...,
23522332
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2380,11 +2360,7 @@ class AsyncRetriever(BaseModel):
23802360
CustomPartitionRouter,
23812361
ListPartitionRouter,
23822362
SubstreamPartitionRouter,
2383-
List[
2384-
Union[
2385-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2386-
]
2387-
],
2363+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
23882364
]
23892365
] = Field(
23902366
[],
@@ -2452,12 +2428,10 @@ class DynamicDeclarativeStream(BaseModel):
24522428
stream_template: DeclarativeStream = Field(
24532429
..., description="Reference to the stream template.", title="Stream Template"
24542430
)
2455-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2456-
Field(
2457-
...,
2458-
description="Component resolve and populates stream templates with components values.",
2459-
title="Components Resolver",
2460-
)
2431+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2432+
...,
2433+
description="Component resolve and populates stream templates with components values.",
2434+
title="Components Resolver",
24612435
)
24622436

24632437

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,9 @@ def create_parent_stream_config(
25302530
)
25312531

25322532
if "*" in model.lazy_read_pointer:
2533-
raise ValueError("The '*' wildcard in 'lazy_read_pointer' is not supported — only direct paths are allowed.")
2533+
raise ValueError(
2534+
"The '*' wildcard in 'lazy_read_pointer' is not supported — only direct paths are allowed."
2535+
)
25342536

25352537
return ParentStreamConfig(
25362538
parent_key=model.parent_key,
@@ -2541,7 +2543,7 @@ def create_parent_stream_config(
25412543
incremental_dependency=model.incremental_dependency or False,
25422544
parameters=model.parameters or {},
25432545
extra_fields=model.extra_fields,
2544-
lazy_read_pointer=model.lazy_read_pointer
2546+
lazy_read_pointer=model.lazy_read_pointer,
25452547
)
25462548

25472549
@staticmethod
@@ -2745,9 +2747,16 @@ def create_simple_retriever(
27452747
model.ignore_stream_slicer_parameters_on_paginated_requests or False
27462748
)
27472749

2748-
if hasattr(model, "partition_router") and model.partition_router and model.partition_router.type == "SubstreamPartitionRouter" and not bool(
2749-
self._connector_state_manager.get_stream_state(name, None)) and any(parent_stream_config.lazy_read_pointer for parent_stream_config in model.partition_router.parent_stream_configs):
2750-
2750+
if (
2751+
hasattr(model, "partition_router")
2752+
and model.partition_router
2753+
and model.partition_router.type == "SubstreamPartitionRouter"
2754+
and not bool(self._connector_state_manager.get_stream_state(name, None))
2755+
and any(
2756+
parent_stream_config.lazy_read_pointer
2757+
for parent_stream_config in model.partition_router.parent_stream_configs
2758+
)
2759+
):
27512760
if incremental_sync.step or incremental_sync.cursor_granularity:
27522761
raise ValueError(
27532762
f"Found more that one slice per parent. LazySimpleRetriever only supports single slice read for stream - {name}."

airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#
44

55

6-
import json
76
import copy
7+
import json
88
import logging
99
from dataclasses import InitVar, dataclass
1010
from typing import TYPE_CHECKING, Any, Iterable, List, Mapping, MutableMapping, Optional, Union
@@ -64,11 +64,16 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None:
6464
for key_path in self.extra_fields
6565
]
6666

67-
self.lazy_read_pointer = [
68-
InterpolatedString.create(path, parameters=parameters)
69-
if isinstance(path, str)
70-
else path for path in self.lazy_read_pointer
71-
] if self.lazy_read_pointer else None
67+
self.lazy_read_pointer = (
68+
[
69+
InterpolatedString.create(path, parameters=parameters)
70+
if isinstance(path, str)
71+
else path
72+
for path in self.lazy_read_pointer
73+
]
74+
if self.lazy_read_pointer
75+
else None
76+
)
7277

7378

7479
@dataclass
@@ -208,7 +213,12 @@ def stream_slices(self) -> Iterable[StreamSlice]:
208213
extracted_extra_fields = self._extract_extra_fields(parent_record, extra_fields)
209214

210215
if parent_stream_config.lazy_read_pointer:
211-
extracted_extra_fields = {"child_response": self._extract_child_response(parent_record, parent_stream_config.lazy_read_pointer), **extracted_extra_fields}
216+
extracted_extra_fields = {
217+
"child_response": self._extract_child_response(
218+
parent_record, parent_stream_config.lazy_read_pointer
219+
),
220+
**extracted_extra_fields,
221+
}
212222

213223
yield StreamSlice(
214224
partition={
@@ -220,7 +230,7 @@ def stream_slices(self) -> Iterable[StreamSlice]:
220230
)
221231

222232
def _extract_child_response(
223-
self, parent_record: MutableMapping[str, Any], pointer
233+
self, parent_record: MutableMapping[str, Any], pointer
224234
) -> requests.Response:
225235
"""Extract child records from a parent record based on lazy pointers."""
226236

0 commit comments

Comments
 (0)