Skip to content

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Sep 16, 2025

fix: update deprecated jsonschema import to use protocols module

Summary

Replaces the deprecated from jsonschema import Validator import with from jsonschema.protocols import Validator to resolve the DeprecationWarning in airbyte_cdk/sources/utils/transform.py. This addresses the warning message:

DeprecationWarning: Importing Validator directly from the jsonschema package is deprecated and will become an ImportError. Import it from jsonschema.protocols instead.

The change removes a try/except import fallback block and uses the new recommended import path directly.

Review & Testing Checklist for Human

  • Verify the deprecation warning is no longer present when running PyAirbyte or CDK code
  • Run a broader test suite to ensure no import errors are introduced in dependent code
  • Check that connectors using the CDK still function correctly with this change

Notes

Summary by CodeRabbit

  • Refactor
    • Streamlined internal type annotations to use a single, consistent source, reducing ambiguity and improving maintainability. No changes to runtime behavior or user-facing functionality.

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>
@Copilot Copilot AI review requested due to automatic review settings September 16, 2025 22:56
Copy link
Contributor

Original prompt from AJ Steers
@Devin - Help me kill this warning:

/home/ubuntu/repos/PyAirbyte/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/utils/transform.py:23: DeprecationWarning: Importing Validator directly from the jsonschema package is deprecated and will become an ImportError. Import it from jsonschema.protocols instead.
  from jsonschema import Validator
/home/ubuntu/.pyenv/versions/3.10.16/lib/python3.10/abc.py:106: ExperimentalClassWarning: This class is experimental. Use at your own risk.
Thread URL: https://airbytehq-team.slack.com/archives/D089P0UPVT4/p1758063057321719?thread_ts=1758063057.321719

Copy link
Contributor

🤖 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

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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 Validator with from 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.

@github-actions github-actions bot added bug Something isn't working security labels Sep 16, 2025
Copy link

👋 Greetings, Airbyte Team Member!

Here are some helpful tips and reminders for your convenience.

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/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-import

Helpful Resources

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
  • /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

📝 Edit this welcome message.

Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

📝 Walkthrough

Walkthrough

Replaced 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

Cohort / File(s) Summary of changes
Type-hint import consolidation
airbyte_cdk/sources/utils/transform.py
Removed try/except import fallback for Validator; added from jsonschema.protocols import Validator; annotations now reference the protocol type directly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug, airbyte-python-cdk

Suggested reviewers

  • pedroslopez
  • brianjlai

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: update deprecated jsonschema import to use protocols module" succinctly and accurately summarizes the primary change—switching the deprecated jsonschema import to the protocols module. It is a single clear sentence directly related to the transform.py changes and PR objectives, and it avoids vague terms or extraneous detail. This makes it easy for a reviewer scanning history to understand the intent.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1758063720-fix-jsonschema-import

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 — verified

Importing Validator from jsonschema.protocols is correct and removes the deprecation.

  • No remaining from jsonschema import Validator occurrences 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b42145 and 8464a30.

📒 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

Copy link

PyTest Results (Fast)

3 747 tests  ±0   3 735 ✅ ±0   6m 17s ⏱️ -2s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 8464a30. ± Comparison against base commit 1b42145.

Copy link

PyTest Results (Full)

3 750 tests   3 738 ✅  11m 10s ⏱️
    1 suites     12 💤
    1 files        0 ❌

Results for commit 8464a30.

@aaronsteers aaronsteers merged commit fd3e4bd into main Sep 17, 2025
30 checks passed
@aaronsteers aaronsteers deleted the devin/1758063720-fix-jsonschema-import branch September 17, 2025 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant