← Back to Pull requests

Fix circular import in the Azure KMS driver #2416

Closed
unknown closed this pull request without merging on Nov 12, 2026 19:01 UTC
View on GitHub
unknown unknown commented on Nov 07, 2026 16:52 UTC
Author

What
----
Importing confluent_kafka.schema_registry.rules.encryption.azurekms.azure_client before azure_driver raises ImportError: cannot import name 'AzureKmsClient' from partially initialized module ... (most likely due to a circular import) on every Python version: azure_client imports the azure_driver module for its key version helpers, and azure_driver imports the AzureKmsClient class from azure_client. For example, pytest tests/schema_registry/test_azure_client.py fails at collection when run on its own. azure_driver now imports the azure_client module rather than the class, as azure_client already does for azure_driver, so the cycle resolves whichever module is imported first.

The new tests/test_imports.py imports every submodule in a fresh interpreter, skipping modules whose optional dependencies are not installed.

This is the part of #2401 that does not depend on Python 3.8.

Checklist
------------------

  • Contains customer facing changes? Including API/behavior changes

  • - azure_client can be imported before azure_driver. No API change.
  • Did you add sufficient unit test and/or integration test coverage for this PR?

  • - tests/test_imports.py, which fails on master when the rules dependencies (tink, Azure SDK) are installed.

    References
    ----------
    Replaces #2401: its Python 3.8 fix is moot once #2406 drops 3.8.

    Test & Review
    ------------

  • Python 3.11.16 and 3.9.25 with requirements/requirements-tests-install.txt: on master, pytest tests/schema_registry/test_azure_client.py errors at collection, and the new test fails with the ImportError; with this change, both files pass (7 tests).

  • Python 3.11.16, pytest tests --ignore=tests/integration: 2544 passed, 16 skipped. The full run does not show the bug on master, because tests/schema_registry/_async/test_avro_serdes_rules.py is collected before test_azure_client.py and imports azure_driver first.

  • Python 3.15.0 and 3.15.0t: the new test passes. The Azure modules are skipped there, since tink has no cp315 wheels.

  • tools/style-format.sh on the changed files, flake8, mypy src/confluent_kafka and tools/unasync.py --check pass.
  • Open questions / Follow-ups
    --------------------------

  • On Python 3.8 the new test fails on confluent_kafka.aio (TypeError: 'type' object is not subscriptable, the bug #2401 fixed). No CI job runs the unit tests on 3.8, and #2406 drops 3.8.
  • 🤖 Generated with Claude Code

    https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN

    Diff: 319 lines (+239 / -80) across 3 files Reviewer: pylaterreur Review duration: 7329m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 319 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.345
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2416"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.0% · Safe to merge
    16.0%