-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Break Python application with status 1 on exception #37390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
maxi297
merged 8 commits into
master
from
maxi297/concurrent-cdk-breaking-with-status-code-not-equal-to-1
Apr 18, 2024
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f79cb89
Fix partitioned state saving issue
maxi297 94bed74
Break Python application with status 1 on exception
maxi297 db60661
Merge branch 'master' into maxi297/concurrent-cdk-breaking-with-statu…
maxi297 333a288
format
maxi297 0e3f08e
Code review
maxi297 58b3272
format
maxi297 cf58448
Merge branch 'master' into maxi297/concurrent-cdk-breaking-with-statu…
maxi297 460939c
flake8
maxi297 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
import logging | ||
from typing import Dict, Iterable, List, Optional, Set | ||
from typing import Dict, Iterable, List, Optional, Set, Mapping | ||
|
||
from airbyte_cdk.models import AirbyteMessage, AirbyteStreamStatus | ||
from airbyte_cdk.models import Type as MessageType | ||
|
@@ -19,8 +19,9 @@ | |
from airbyte_cdk.sources.utils.record_helper import stream_data_to_airbyte_message | ||
from airbyte_cdk.sources.utils.slice_logger import SliceLogger | ||
from airbyte_cdk.utils import AirbyteTracedException | ||
from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets | ||
from airbyte_cdk.utils.stream_status_utils import as_airbyte_message as stream_status_as_airbyte_message | ||
from airbyte_protocol.models import StreamDescriptor | ||
from airbyte_protocol.models import StreamDescriptor, FailureType | ||
|
||
|
||
class ConcurrentReadProcessor: | ||
|
@@ -100,7 +101,8 @@ def on_partition_complete_sentinel(self, sentinel: PartitionCompleteSentinel) -> | |
partition = sentinel.partition | ||
|
||
try: | ||
partition.close() | ||
if sentinel.is_successful: | ||
partition.close() | ||
except Exception as exception: | ||
self._flag_exception(partition.stream_name(), exception) | ||
yield AirbyteTracedException.from_exception( | ||
|
@@ -174,6 +176,11 @@ def start_next_partition_generator(self) -> Optional[AirbyteMessage]: | |
else: | ||
return None | ||
|
||
@staticmethod | ||
def _generate_failed_streams_error_message(stream_failures: Mapping[str, List[Exception]]) -> str: | ||
failures = ", ".join([f"{stream}: {filter_secrets(exception.__repr__())}" for stream, exceptions in stream_failures.items() for exception in exceptions]) | ||
return f"During the sync, the following streams did not sync successfully: {failures}" | ||
|
||
def is_done(self) -> bool: | ||
""" | ||
This method is called to check if the sync is done. | ||
|
@@ -182,7 +189,15 @@ def is_done(self) -> bool: | |
2. There are no more streams to read from | ||
3. All partitions for all streams are closed | ||
""" | ||
return all([self._is_stream_done(stream_name) for stream_name in self._stream_name_to_instance.keys()]) | ||
is_done = all([self._is_stream_done(stream_name) for stream_name in self._stream_name_to_instance.keys()]) | ||
if is_done and self._exceptions_per_stream_name: | ||
error_message = self._generate_failed_streams_error_message(self._exceptions_per_stream_name) | ||
self._logger.info(error_message) | ||
# We still raise at least one exception when a stream raises an exception because the platform currently relies | ||
# on a non-zero exit code to determine if a sync attempt has failed. We also raise the exception as a config_error | ||
# type because this combined error isn't actionable, but rather the previously emitted individual errors. | ||
raise AirbyteTracedException(message=error_message, internal_message="Concurrent read failure", failure_type=FailureType.config_error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a internal_message is different than abstract_source. I had to add an internal message as the scenario framework will assert on the internal_message. Leaving this empty would generate |
||
return is_done | ||
|
||
def _is_stream_done(self, stream_name: str) -> bool: | ||
return stream_name in self._streams_done | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.