Skip to content
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

Source S3: encoding validation fix, refactor and test #28730

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-s3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ COPY source_s3 ./source_s3
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=3.1.0
LABEL io.airbyte.version=3.1.1
LABEL io.airbyte.name=airbyte/source-s3
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-s3/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data:
connectorSubtype: file
connectorType: source
definitionId: 69589781-7828-43c5-9f63-8925b1c1ccc2
dockerImageTag: 3.1.0
dockerImageTag: 3.1.1
dockerRepository: airbyte/source-s3
githubIssueLabel: source-s3
icon: s3.svg
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-s3/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"airbyte-cdk",
"pyarrow==9.0.0",
"smart-open[s3]==5.1.0",
"wcmatch==8.2",
"wcmatch==8.4",
"dill==0.3.4",
"pytz",
"fastavro==1.4.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def _validate_field(
if field_value in disallow_values:
return f"{field_name} can not be {field_value}"

@staticmethod
def _validate_encoding(encoding: str) -> None:
try:
codecs.lookup(encoding)
except LookupError as e:
# UTF8 is the default encoding value, so there is no problem if `encoding` is not set manually
if encoding != "":
raise AirbyteTracedException(str(e), str(e), failure_type=FailureType.config_error)

@classmethod
def _validate_options(cls, validator: Callable, options_name: str, format_: Mapping[str, Any]) -> Optional[str]:
options = format_.get(options_name, "{}")
Expand Down Expand Up @@ -98,10 +107,7 @@ def _validate_config(self, config: Mapping[str, Any]):
if error_message:
raise AirbyteTracedException(error_message, error_message, failure_type=FailureType.config_error)

try:
codecs.lookup(format_.get("encoding"))
except LookupError:
raise AirbyteTracedException(error_message, error_message, failure_type=FailureType.config_error)
self._validate_encoding(format_.get("encoding", ""))

def _read_options(self) -> Mapping[str, str]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import random
import shutil
import string
from contextlib import nullcontext as does_not_raise
from pathlib import Path
from typing import Any, List, Mapping, Tuple
from unittest.mock import Mock

import pendulum
import pytest
from airbyte_cdk.utils.traced_exception import AirbyteTracedException
from smart_open import open as smart_open
from source_s3.source_files_abstract.file_info import FileInfo
from source_s3.source_files_abstract.formats.csv_parser import CsvParser
Expand Down Expand Up @@ -412,3 +415,16 @@ def test_big_file(self) -> None:
read_count += 1
assert read_count == expected_count
expected_file.close()

@pytest.mark.parametrize(
"encoding, expectation",
(
("UTF8", does_not_raise()),
("", does_not_raise()),
("R2D2", pytest.raises(AirbyteTracedException)),
)
)
def test_encoding_validation(self, encoding, expectation) -> None:
parser = CsvParser(format=Mock(), master_schema=Mock())
with expectation:
parser._validate_encoding(encoding)
1 change: 1 addition & 0 deletions docs/integrations/sources/s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Be cautious when raising this value too high, as it may result in Out Of Memory

| Version | Date | Pull Request | Subject |
| :------ | :--------- | :-------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------- |
| 3.1.1 | 2023-07-26 | [28730](https://github.com/airbytehq/airbyte/pull/28730) | Add human readable error message and improve validation for encoding field when it empty |
| 3.1.0 | 2023-06-26 | [27725](https://github.com/airbytehq/airbyte/pull/27725) | License Update: Elv2 |
| 3.0.3 | 2023-06-23 | [27651](https://github.com/airbytehq/airbyte/pull/27651) | Handle Bucket Access Errors |
| 3.0.2 | 2023-06-22 | [27611](https://github.com/airbytehq/airbyte/pull/27611) | Fix start date |
Expand Down