Skip to content

Commit 9130b35

Browse files
authored
fix: gracefully continue on tempfile cleanup failure (#103)
1 parent 2aabfe6 commit 9130b35

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

airbyte_cdk/entrypoint.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from typing import Any, DefaultDict, Iterable, List, Mapping, Optional
1616
from urllib.parse import urlparse
1717

18+
import orjson
1819
import requests
19-
from orjson import orjson
2020
from requests import PreparedRequest, Response, Session
2121

2222
from airbyte_cdk.connector import TConfig
@@ -129,7 +129,11 @@ def run(self, parsed_args: argparse.Namespace) -> Iterable[str]:
129129

130130
source_spec: ConnectorSpecification = self.source.spec(self.logger)
131131
try:
132-
with tempfile.TemporaryDirectory() as temp_dir:
132+
with tempfile.TemporaryDirectory(
133+
# Cleanup can fail on Windows due to file locks. Ignore if so,
134+
# rather than failing the whole process.
135+
ignore_cleanup_errors=True,
136+
) as temp_dir:
133137
os.environ[ENV_REQUEST_CACHE_PATH] = (
134138
temp_dir # set this as default directory for request_cache to store *.sqlite files
135139
)
@@ -246,12 +250,18 @@ def handle_record_counts(
246250
) -> AirbyteMessage:
247251
match message.type:
248252
case Type.RECORD:
253+
if message.record is None:
254+
raise ValueError("Record message must have a record attribute")
255+
249256
stream_message_count[
250257
HashableStreamDescriptor(
251258
name=message.record.stream, namespace=message.record.namespace
252259
)
253260
] += 1.0 # type: ignore[union-attr] # record has `stream` and `namespace`
254261
case Type.STATE:
262+
if message.state is None:
263+
raise ValueError("State message must have a state attribute")
264+
255265
stream_descriptor = message_utils.get_stream_descriptor(message)
256266

257267
# Set record count from the counter onto the state message

unit_tests/sources/streams/test_call_rate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ class StubDummyCacheHttpStream(StubDummyHttpStream):
4747
@pytest.fixture(name="enable_cache")
4848
def enable_cache_fixture():
4949
prev_cache_path = os.environ.get(ENV_REQUEST_CACHE_PATH)
50-
with tempfile.TemporaryDirectory() as temp_dir:
50+
with tempfile.TemporaryDirectory(
51+
# Cleanup can fail on Windows due to file locks. Ignore if so,
52+
# rather than failing the whole process.
53+
ignore_cleanup_errors=True,
54+
) as temp_dir:
5155
os.environ[ENV_REQUEST_CACHE_PATH] = temp_dir
5256
yield
5357

0 commit comments

Comments
 (0)