Skip to content

Commit 7b16aab

Browse files
author
Oleksandr Bazarnov
committed
add __requires_migration: bool flag to manifest config
1 parent a3679a3 commit 7b16aab

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

airbyte_cdk/connector_builder/connector_builder_handler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,23 @@ def get_limits(config: Mapping[str, Any]) -> TestLimits:
5656
return TestLimits(max_records, max_pages_per_slice, max_slices, max_streams)
5757

5858

59+
def requires_migration(config: Mapping[str, Any]) -> bool:
60+
"""
61+
Check if the manifest requires migration.
62+
63+
:param config: The config to check
64+
:return: True if the manifest requires migration, False otherwise
65+
"""
66+
return config.get("__requires_migration", False)
67+
68+
5969
def create_source(config: Mapping[str, Any], limits: TestLimits) -> ManifestDeclarativeSource:
6070
manifest = config["__injected_declarative_manifest"]
6171
return ManifestDeclarativeSource(
6272
config=config,
6373
emit_connector_builder_messages=True,
6474
source_config=manifest,
75+
migrate_manifest=requires_migration(config),
6576
component_factory=ModelToComponentFactory(
6677
emit_connector_builder_messages=True,
6778
limit_pages_fetched_per_slice=limits.max_pages_per_slice,

airbyte_cdk/sources/declarative/manifest_declarative_source.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ def __init__(
7272
debug: bool = False,
7373
emit_connector_builder_messages: bool = False,
7474
component_factory: Optional[ModelToComponentFactory] = None,
75+
migrate_manifest: Optional[bool] = False,
7576
) -> None:
7677
"""
7778
Args:
7879
config: The provided config dict.
7980
source_config: The manifest of low-code components that describe the source connector.
80-
debug: True if debug mode is enabled.
81-
emit_connector_builder_messages: True if messages should be emitted to the connector builder.
82-
component_factory: optional factory if ModelToComponentFactory's default behavior needs to be tweaked.
81+
debug: bool True if debug mode is enabled.
82+
emit_connector_builder_messages: Optional[bool] True if messages should be emitted to the connector builder.
83+
component_factory: Optional factory if ModelToComponentFactory's default behavior needs to be tweaked.
84+
migrate_manifest: Optional[bool] if the manifest should be migrated to pick up the latest declarative component schema changes at runtime.
8385
"""
8486
self.logger = logging.getLogger(f"airbyte.{self.name}")
8587

@@ -96,11 +98,12 @@ def __init__(
9698
"", resolved_source_config, {}
9799
)
98100

99-
migrated_source_config = ManifestMigrationHandler(
100-
propagated_source_config
101-
).apply_migrations()
101+
if migrate_manifest:
102+
propagated_source_config = ManifestMigrationHandler(
103+
propagated_source_config
104+
).apply_migrations()
102105

103-
self._source_config = migrated_source_config
106+
self._source_config = propagated_source_config
104107
self._debug = debug
105108
self._emit_connector_builder_messages = emit_connector_builder_messages
106109
self._constructor = (

unit_tests/connector_builder/test_connector_builder_handler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ def test_resolve_manifest(valid_resolve_manifest_config_file):
606606
},
607607
"requester": {
608608
"type": "HttpRequester",
609+
"path": "/v3/marketing/lists",
609610
"authenticator": {
610611
"type": "BearerAuthenticator",
611612
"api_token": "{{ config.apikey }}",
@@ -617,7 +618,7 @@ def test_resolve_manifest(valid_resolve_manifest_config_file):
617618
"request_parameters": {"a_param": "10"},
618619
"name": _stream_name,
619620
"primary_key": _stream_primary_key,
620-
"url": _stream_url_base + "/v3/marketing/lists",
621+
"url_base": _stream_url_base,
621622
"$parameters": _stream_options,
622623
},
623624
"partition_router": {
@@ -1495,6 +1496,7 @@ def test_full_resolve_manifest(valid_resolve_manifest_config_file):
14951496
},
14961497
},
14971498
"requester": {
1499+
"path": "/v3/marketing/lists",
14981500
"authenticator": {
14991501
"type": "BearerAuthenticator",
15001502
"api_token": "{{ config.apikey }}",
@@ -1511,7 +1513,7 @@ def test_full_resolve_manifest(valid_resolve_manifest_config_file):
15111513
"type": "HttpRequester",
15121514
"name": "stream_with_custom_requester",
15131515
"primary_key": "id",
1514-
"url": "https://10.0.27.27/api/v1/v3/marketing/lists",
1516+
"url_base": "https://10.0.27.27/api/v1/",
15151517
"$parameters": {
15161518
"name": "stream_with_custom_requester",
15171519
"primary_key": "id",

0 commit comments

Comments
 (0)