fix: update deprecated jsonschema import to use protocols module#763
Conversation
Replace deprecated 'from jsonschema import Validator' with 'from jsonschema.protocols import Validator' to resolve DeprecationWarning about direct import from jsonschema package. Co-Authored-By: AJ Steers <aj@airbyte.io>
Original prompt from AJ Steers |
🤖 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:
|
There was a problem hiding this comment.
Pull Request Overview
This PR updates the deprecated jsonschema import to use the new protocols module, addressing a deprecation warning. The change removes a try/except import fallback block and replaces it with the recommended import path for the Validator class.
- Replaces deprecated
from jsonschema import Validatorwithfrom jsonschema.protocols import Validator - Removes the try/except fallback import mechanism that was handling the old import path
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. Testing 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/1758063720-fix-jsonschema-import#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/1758063720-fix-jsonschema-importHelpful ResourcesPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
📝 WalkthroughWalkthroughReplaced the fallback import logic for jsonschema’s Validator with a single direct import from jsonschema.protocols. Updated type annotations to reference the protocol type explicitly. No runtime behavior or control-flow changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Would you like to confirm that supported jsonschema versions all expose Validator under jsonschema.protocols to avoid compatibility regressions, wdyt? Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
airbyte_cdk/sources/utils/transform.py (2)
10-12: Optional: alias to avoid confusion with Airbyte’s own Validator.Since we also have airbyte_cdk.sources.declarative.validators.validator.Validator elsewhere, shall we alias the jsonschema type for readability, wdyt?
-from jsonschema.protocols import Validator +from jsonschema.protocols import Validator as JSONSchemaValidator @@ - def normalizator( - validator_instance: Validator, + def normalizator( + validator_instance: JSONSchemaValidator,Also applies to: 187-193
11-11: Correct fix: import Validator from jsonschema.protocols — verifiedImporting Validator from jsonschema.protocols is correct and removes the deprecation.
- No remaining
from jsonschema import Validatoroccurrences found.- pyproject.toml pins jsonschema = ">=4.17.3,<5.0" (pyproject.toml:46) — this satisfies protocols.Validator (available since >=4.8.0) but is below the "ideally >=4.19.0" suggestion.
Raise the minimum to >=4.19.0 to avoid any deprecation-era surprises, or leave as-is? wdyt?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
airbyte_cdk/sources/utils/transform.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
airbyte_cdk/sources/utils/transform.py (1)
airbyte_cdk/sources/declarative/validators/validator.py (1)
Validator(9-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Check: destination-motherduck
- GitHub Check: Check: source-pokeapi
- GitHub Check: Check: source-hardcoded-records
- GitHub Check: Check: source-intercom
- GitHub Check: Check: source-shopify
- GitHub Check: Pytest (All, Python 3.13, Ubuntu)
- GitHub Check: Pytest (All, Python 3.12, Ubuntu)
- GitHub Check: Pytest (All, Python 3.11, Ubuntu)
- GitHub Check: Pytest (All, Python 3.10, Ubuntu)
- GitHub Check: Pytest (Fast)
- GitHub Check: SDM Docker Image Build
- GitHub Check: Manifest Server Docker Image Build
PyTest Results (Full)3 750 tests 3 738 ✅ 11m 10s ⏱️ Results for commit 8464a30. |
fix: update deprecated jsonschema import to use protocols module
Summary
Replaces the deprecated
from jsonschema import Validatorimport withfrom jsonschema.protocols import Validatorto resolve the DeprecationWarning inairbyte_cdk/sources/utils/transform.py. This addresses the warning message:The change removes a try/except import fallback block and uses the new recommended import path directly.
Review & Testing Checklist for Human
Notes
Summary by CodeRabbit