Skip to content

Commit b0001b8

Browse files
author
maxime.c
committed
make properties from endpoint cache thread safe
1 parent e8ab340 commit b0001b8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

airbyte_cdk/sources/declarative/requesters/query_properties/properties_from_endpoint.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
2-
2+
import threading
33
from dataclasses import InitVar, dataclass
44
from typing import Any, Iterable, List, Mapping, Optional
55

66
import dpath
77

88
from airbyte_cdk.sources.declarative.interpolation import InterpolatedString
99
from airbyte_cdk.sources.declarative.retrievers import Retriever
10-
from airbyte_cdk.sources.types import Config, StreamSlice
10+
from airbyte_cdk.sources.types import Config
1111

1212

1313
@dataclass
@@ -25,19 +25,22 @@ class PropertiesFromEndpoint:
2525
_cached_properties: Optional[List[str]] = None
2626

2727
def __post_init__(self, parameters: Mapping[str, Any]) -> None:
28+
self._lock = threading.RLock()
2829
self._property_field_path = [
2930
InterpolatedString(string=property_field, parameters=parameters)
3031
for property_field in self.property_field_path
3132
]
3233

3334
def get_properties_from_endpoint(self) -> List[str]:
3435
if self._cached_properties is None:
35-
self._cached_properties = list(
36-
map(
37-
self._get_property, # type: ignore # SimpleRetriever and AsyncRetriever only returns Record. Should we change the return type of Retriever.read_records?
38-
self.retriever.read_records(records_schema={}, stream_slice=None),
39-
)
40-
)
36+
with self._lock:
37+
if self._cached_properties is None:
38+
self._cached_properties = list(
39+
map(
40+
self._get_property, # type: ignore # SimpleRetriever and AsyncRetriever only returns Record. Should we change the return type of Retriever.read_records?
41+
self.retriever.read_records(records_schema={}, stream_slice=None),
42+
)
43+
)
4144
return self._cached_properties
4245

4346
def _get_property(self, property_obj: Mapping[str, Any]) -> str:

0 commit comments

Comments
 (0)