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 Google Sheets: handle config errors #26097

Merged
merged 9 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ COPY source_google_sheets ./source_google_sheets
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.2.37
LABEL io.airbyte.version=0.2.38
LABEL io.airbyte.name=airbyte/source-google-sheets
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ acceptance_tests:
- config_path: secrets/service_config.json
status: succeed
- config_path: integration_tests/invalid_config.json
status: failed
status: exception
discovery:
tests:
- config_path: secrets/service_config.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data:
connectorSubtype: file
connectorType: source
definitionId: 71607ba1-c0ac-4799-8049-7f4b90dd50f7
dockerImageTag: 0.2.37
dockerImageTag: 0.2.38
dockerRepository: airbyte/source-google-sheets
githubIssueLabel: source-google-sheets
icon: google-sheets.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from google.auth import exceptions as google_exceptions
from requests.status_codes import codes as status_codes

from airbyte_cdk.models import FailureType
from airbyte_cdk.utils import AirbyteTracedException
from .client import GoogleSheetsClient
from .helpers import Helpers
from .models.spreadsheet import Spreadsheet
Expand All @@ -41,9 +43,6 @@ class SourceGoogleSheets(Source):
Spreadsheets API Reference: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets
"""

def __init__(self):
super().__init__()

def check(self, logger: AirbyteLogger, config: json) -> AirbyteConnectionStatus:
# Check involves verifying that the specified spreadsheet is reachable with our credentials.
try:
Expand All @@ -56,18 +55,22 @@ def check(self, logger: AirbyteLogger, config: json) -> AirbyteConnectionStatus:
try:
spreadsheet = client.get(spreadsheetId=spreadsheet_id, includeGridData=False)
except errors.HttpError as err:
reason = str(err)
message = "Config error: "
# Give a clearer message if it's a common error like 404.
if err.resp.status == status_codes.NOT_FOUND:
reason = "Requested spreadsheet was not found."
logger.error(f"Formatted error: {reason}")
return AirbyteConnectionStatus(
status=Status.FAILED, message=f"Unable to connect with the provided credentials to spreadsheet. Error: {reason}"
)
message += "The spreadsheet link is not valid. Enter the URL of the Google spreadsheet you want to sync."
raise AirbyteTracedException(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add unit tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests added

message=message,
internal_message=message,
failure_type=FailureType.config_error,
) from err
except google_exceptions.GoogleAuthError as err:
return AirbyteConnectionStatus(
status=Status.FAILED, message=f"Unable to connect with the provided credentials to spreadsheet. Authentication Error: {err}"
)
message = "Access to the spreadsheet expired or was revoked. Re-authenticate to restore access."
raise AirbyteTracedException(
message=message,
internal_message=message,
failure_type=FailureType.config_error,
) from err

# Check for duplicate headers
spreadsheet_metadata = Spreadsheet.parse_obj(spreadsheet)
Expand Down
3 changes: 2 additions & 1 deletion docs/integrations/sources/google-sheets.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ The [Google API rate limit](https://developers.google.com/sheets/api/limits) is
## Changelog

| Version | Date | Pull Request | Subject |
|---------| ---------- | -------------------------------------------------------- |-------------------------------------------------------------------------------|
|---------|------------|----------------------------------------------------------|-------------------------------------------------------------------------------|
| 0.2.38 | 2023-05-16 | [26097](https://github.com/airbytehq/airbyte/pull/26097) | Refactor config error |
| 0.2.37 | 2023-02-21 | [23292](https://github.com/airbytehq/airbyte/pull/23292) | Skip non grid sheets. |
| 0.2.36 | 2023-02-21 | [23272](https://github.com/airbytehq/airbyte/pull/23272) | Handle empty sheets gracefully. |
| 0.2.35 | 2023-02-23 | [23057](https://github.com/airbytehq/airbyte/pull/23057) | Slugify column names |
Expand Down
Loading