fix: improve serialization error messages and add default=str fallback#965
Draft
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Draft
fix: improve serialization error messages and add default=str fallback#965devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
- Replace misleading warning message with clear, guideline-compliant text - Add json.dumps(default=str) fallback to prevent deadlocks when both orjson and json.dumps fail on non-serializable types (e.g. complex) - Catch specific TypeError instead of broad Exception for json fallback - Log technical details at DEBUG level, user-facing messages at WARNING - Add separate flag to log second fallback warning only once Resolves airbytehq/airbyte-internal-issues#16049 Co-Authored-By: bot_apk <apk@cognition.ai>
Contributor
Author
🤖 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/1774545807-improve-serialization-error-message#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/1774545807-improve-serialization-error-messagePR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
| "The value was converted to a string representation." | ||
| ) | ||
| logger.debug("json serialization error: %s", json_error) | ||
| _HAS_LOGGED_FOR_SERIALIZATION_FALLBACK = True |
Contributor
Author
There was a problem hiding this comment.
This is a false positive. _HAS_LOGGED_FOR_SERIALIZATION_FALLBACK is already declared at module level on line 52 and is read/written inside the function via global _HAS_LOGGED_FOR_SERIALIZATION_FALLBACK. The suggested fix describes exactly what this PR already does.
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
Improves the user-facing warning messages in
airbyte_message_to_string()and adds a second serialization fallback to prevent unhandled exceptions (and consequent deadlocks in the concurrent source pipeline) when record data contains types that neitherorjsonnor stdlibjsoncan serialize.Before: The warning said "There was an error during the serialization of an AirbyteMessage:
Type is not JSON serializable: complex. This might impact the sync performances." — misleading (actual impact is a deadlock, not a perf hit), leaks implementation details, andjson.dumps()on the next line could also throw unhandled.After:
"Record serialization fell back to slower method. Sync will continue with reduced performance.""Record contains a value that could not be serialized to JSON. The value was converted to a string representation."Resolves https://github.com/airbytehq/airbyte-internal-issues/issues/16049
Related: #954 (overlapping scope — this PR supersedes it with the addition of message improvements)
Review & Testing Checklist for Human
TypeErrorcatch scope may be too narrow: The inner fallback catchesTypeErroronly.json.dumps()can also raiseValueError(circular references) orOverflowError. If those occur, the exception still propagates unhandled. Decide if the catch should be broadened toExceptionhere as a last-resort deadlock prevention, or if the narrowTypeErroris acceptable since circular references in AirbyteMessage data are extremely unlikely (data originates from JSON API responses).default=str: When this fallback fires, non-serializable values are silently converted to strings (e.g.,complex(0.0423, 0)→"(0.0423+0j)"). This is data quality degradation. Confirm this is acceptable as a last-resort path, and that connector-level fixes (like the companion PR fix(source-google-search-console): guard numeric fields against complex types (AI-Triage PR) airbyte#75426 for source-google-search-console) are the right place to handle data correctness.source-google-search-consolewithcomplextype values. Ideally, run the connector with asearch_analytics_by_querystream to confirm the sync completes without hanging.Notes
complexvalues entering the data flow was separately fixed in CDK PR #579 (Jinja interpolation rejecting complex types, merged in v6.54.5). This PR hardens the serialization layer as defense-in-depth.semantic-pr-release-drafter— no manual version bump is needed. Thefix:title prefix will trigger a patch release.Link to Devin session: https://app.devin.ai/sessions/132db25cd0f34fa995908b456e5ee57c