Skip to content

Commit a308674

Browse files
author
Oleksandr Bazarnov
committed
updated
1 parent ddfde29 commit a308674

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

airbyte_cdk/sources/declarative/manifest_declarative_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def dynamic_streams(self) -> List[Dict[str, Any]]:
125125
)
126126

127127
def deprecation_warnings(self) -> List[AirbyteLogMessage]:
128-
return self._constructor.get_model_deprecations() or []
128+
return self._constructor.get_model_deprecations()
129129

130130
@property
131131
def connection_checker(self) -> ConnectionChecker:

airbyte_cdk/sources/declarative/models/base_model_with_deprecations.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class BaseModelWithDeprecations(BaseModel):
3131
This class is used to create models that can have deprecated fields
3232
and show warnings when those fields are accessed or initialized.
3333
34-
The `_deprecation_logs` attribute is storred in the model itself.
35-
The collected deprecation warnings are further proparated to the Airbyte log messages,
34+
The `_deprecation_logs` attribute is stored in the model itself.
35+
The collected deprecation warnings are further propagated to the Airbyte log messages,
3636
during the component creation process, in `model_to_component._collect_model_deprecations()`.
3737
3838
The component implementation is not responsible for handling the deprecation warnings,
@@ -46,14 +46,14 @@ class Config:
4646

4747
extra = "allow"
4848

49-
_deprecation_logs: List[AirbyteLogMessage] = []
50-
5149
def __init__(self, **data: Any) -> None:
5250
"""
5351
Show warnings for deprecated fields during component initialization.
5452
"""
55-
model_fields = self.__fields__
5653

54+
self._deprecation_logs: List[AirbyteLogMessage] = []
55+
56+
model_fields = self.__fields__
5757
for field_name in data:
5858
if field_name in model_fields:
5959
is_deprecated_field = model_fields[field_name].field_info.extra.get(
@@ -74,7 +74,6 @@ def __getattribute__(self, name: str) -> Any:
7474
"""
7575

7676
value = super().__getattribute__(name)
77-
7877
try:
7978
model_fields = super().__getattribute__(FIELDS_TAG)
8079
field_info = model_fields.get(name)

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def __init__(
589589
self._api_budget: Optional[Union[APIBudget, HttpAPIBudget]] = None
590590
self._job_tracker: JobTracker = JobTracker(max_concurrent_async_job_count or 1)
591591
# placeholder for deprecation warnings
592-
self._deprecation_logs: List[AirbyteLogMessage] = []
592+
self._collected_deprecation_logs: List[AirbyteLogMessage] = []
593593

594594
def _init_mappings(self) -> None:
595595
self.PYDANTIC_MODEL_TO_CONSTRUCTOR: Mapping[Type[BaseModel], Callable[..., Any]] = {
@@ -747,14 +747,22 @@ def get_model_deprecations(self) -> List[Any]:
747747
"""
748748
Returns the deprecation warnings that were collected during the creation of components.
749749
"""
750-
return self._deprecation_logs
750+
return self._collected_deprecation_logs
751751

752752
def _collect_model_deprecations(self, model: BaseModelWithDeprecations) -> None:
753+
"""
754+
Collects deprecation logs from the given model and appends any new logs to the internal collection.
755+
756+
This method checks if the provided model has deprecation logs (identified by the presence of the DEPRECATION_LOGS_TAG attribute and a non-None `_deprecation_logs` property). It iterates through each deprecation log in the model and appends it to the `_collected_deprecation_logs` list if it has not already been collected, ensuring that duplicate logs are avoided.
757+
758+
Args:
759+
model (BaseModelWithDeprecations): The model instance from which to collect deprecation logs.
760+
"""
753761
if hasattr(model, DEPRECATION_LOGS_TAG) and model._deprecation_logs is not None:
754762
for log in model._deprecation_logs:
755763
# avoid duplicates for deprecation logs observed.
756-
if log not in self._deprecation_logs:
757-
self._deprecation_logs.append(log)
764+
if log not in self._collected_deprecation_logs:
765+
self._collected_deprecation_logs.append(log)
758766

759767
@staticmethod
760768
def create_added_field_definition(

0 commit comments

Comments
 (0)