Skip to content

fix: use isinstance() fallback for exception subclass matching in HttpStatusErrorHandler#1006

Draft
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1777536479-fix-isinstance-error-mapping
Draft

fix: use isinstance() fallback for exception subclass matching in HttpStatusErrorHandler#1006
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1777536479-fix-isinstance-error-mapping

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

HttpStatusErrorHandler.interpret_response() used exact class matching (dict.get(exception.__class__)) to look up exception types in the error mapping. The DEFAULT_ERROR_MAPPING maps RequestException to transient_error, but when a subclass like ConnectionError or ChunkedEncodingError was encountered, dict.get(ConnectionError) returned None because it is not the same class as RequestException.

This caused transient network errors to fall through to the else branch, producing the misleading message "Unexpected exception in error handler" and classifying them as system_error instead of transient_error.

Fix: After the exact dict.get() lookup fails, iterate through the mapping's exception-type keys and use isinstance() to find a match. Exact class match still takes precedence for performance and specificity.

Resolves https://github.com/airbytehq/oncall/issues/12124:

Declarative-First Evaluation

Not applicable — this is a CDK-level fix in the imperative HTTP error handler infrastructure, not a connector-level change.

Test Coverage

Added 7 new test cases covering the fix:

  • Parametrized subclass tests (ConnectionError, ChunkedEncodingError, ReadTimeout, ConnectTimeout) — all resolve to transient_error via the RequestException mapping
  • Custom exception mapping test — verifies isinstance fallback works with user-provided mappings
  • Precedence test — verifies exact class match takes priority over isinstance fallback
  • Existing tests for RequestException (exact match), Exception (unmapped), and other paths continue to pass

Breaking Change Evaluation

Not a breaking change. The fix only adds a fallback lookup path — existing exact-match behavior is preserved. No public API, schema, spec, or state format changes.

Review & Testing Checklist for Human

  • Verify the isinstance() fallback iteration order is acceptable (it uses dict insertion order, matching the first parent class found)
  • Confirm that the issubclass(mapped_key, Exception) guard is sufficient to skip non-exception keys (int status codes) during iteration

Notes

  • The CDK uses semantic-pr-release-drafter for versioning, so no manual version bump is needed.
  • This fix benefits all connectors using HttpStatusErrorHandler (or the default error handler) without requiring any connector-level changes.

Link to Devin session: https://app.devin.ai/sessions/4550ef11ab60443096c77cfe3fc6854f

…tusErrorHandler

The interpret_response() method used exact class matching (dict.get) to
look up exception types in the error mapping. This caused subclasses of
RequestException (e.g. ConnectionError, ChunkedEncodingError, ReadTimeout)
to fall through to the else branch, producing misleading 'Unexpected
exception in error handler' messages classified as system_error instead
of transient_error.

Add an isinstance()-based fallback that iterates through exception type
keys in the mapping when exact class lookup returns None. Exact match
still takes precedence for performance and specificity.

Co-Authored-By: bot_apk <apk@cognition.ai>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link
Copy Markdown

👋 Greetings, Airbyte Team Member!

Here are some helpful tips and reminders for your convenience.

💡 Show Tips and Tricks

Testing This CDK Version

You 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/1777536479-fix-isinstance-error-mapping#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/1777536479-fix-isinstance-error-mapping

PR Slash Commands

Airbyte Maintainers can execute the following slash commands on your PR:

  • /autofix - Fixes most formatting and linting issues
  • /poetry-lock - Updates poetry.lock file
  • /test - Runs connector tests with the updated CDK
  • /prerelease - Triggers a prerelease publish with default arguments
  • /poe build - Regenerate git-committed build artifacts, such as the pydantic models which are generated from the manifest JSON schema in YAML.
  • /poe <command> - Runs any poe command in the CDK environment
📚 Show Repo Guidance

Helpful Resources

📝 Edit this welcome message.

@github-actions
Copy link
Copy Markdown

PyTest Results (Fast)

4 046 tests  +6   4 035 ✅ +6   7m 56s ⏱️ +11s
    1 suites ±0      11 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit ff9ab21. ± Comparison against base commit 886fcf8.

@github-actions
Copy link
Copy Markdown

PyTest Results (Full)

4 049 tests  +6   4 037 ✅ +6   10m 59s ⏱️ -24s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit ff9ab21. ± Comparison against base commit 886fcf8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants