fix(low-code): identify the failing response when JSON decoding fails - #1108
Draft
Airbyte Support (Airbyte-Support) wants to merge 2 commits into
Draft
fix(low-code): identify the failing response when JSON decoding fails#1108Airbyte Support (Airbyte-Support) wants to merge 2 commits into
Airbyte Support (Airbyte-Support) wants to merge 2 commits into
Conversation
Co-Authored-By: syed.khadeer@airbyte.io <cloud-support@airbyte.io>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou can test this version of the CDK using the following: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1786079355-json-decoder-diagnostics#egg=airbyte-python-cdk[dev]' --help
# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1786079355-json-decoder-diagnosticsPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
Comment on lines
+49
to
+54
| filter_secrets( | ||
| "Failed to decode JSON response: " | ||
| f"method={request_method}, url={response.url}, status_code={response.status_code}, " | ||
| f"content_type={response.headers.get('Content-Type')}, body_length={len(body)}, " | ||
| f"body_preview={body_preview!r}, error={exc}" | ||
| ) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
JsonDecoder.decodedeliberately swallows every decode exception and yields{}so that a bad body looks like "no records". That is fine as a resilience choice, but the only trace left behind isJsonParser's terse line:No URL, no status code, no content type, no body. When a store or API intermittently answers
HTTP 200with an empty or HTML body, a Cloud sync reports success with 0 records and nothing in the log says which request went wrong.This adds that context at the
JsonDecoderboundary, where therequests.Responseis still in hand:Sample output for a 200 with an empty body:
Notes on the choices:
{}, so no connector starts failing on bodies it used to tolerate.filter_secretsis required, not cosmetic. Some connectors put API keys in query params, soresponse.urland echoed bodies can carry credentials. The body preview is capped at 200 bytes.[]and{}reach theif not has_yielded: yield {}path without raising, so they produce no log line. Covered by a test that asserts zero log records.JsonParser._parse_json's existinglogger.erroris left at error level:CompositeRawDecoderuses that parser directly, without going throughJsonDecoder, so lowering it would blind those paths.Found while diagnosing a WooCommerce Cloud connection whose
ordersstream reported 0 records on every incremental sync. The store was answering some/ordersrequests with a non-JSON 200; the terse log gave no way to tell which window was affected.Follow-up worth a separate look, not addressed here: each failed response emits the parse error three times, i.e. the response body appears to be decoded three times per read.
Test plan
unit_tests/sources/declarative/decoders/test_json_decoder.pycover an empty 200 body, an HTML 200 body, secret filtering of URL and body, and the empty-JSON-array case asserting no log output.pytest unit_tests/sources/declarative/decoders/test_json_decoder.py→ 10 passed;ruff check,ruff format --check, andmypy airbyte_cdkall clean.source-woocommercemanifest throughsource-declarative-manifest readagainst a local mock servingHTTP 200with an empty body and with<html>error</html>: both produce the new line, both still exit 0 with 0 records and an unchanged cursor.Link to Devin session: https://app.devin.ai/sessions/d3561474f87e49e782f680f809784497
Requested by: Airbyte Support (@Airbyte-Support)