Fix KafkaBaseHook.test_connection missing oauth_cb for managed Kafka#69507
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
Fix KafkaBaseHook.test_connection missing oauth_cb for managed Kafka#69507TimurRakhmatullin86 wants to merge 1 commit into
TimurRakhmatullin86 wants to merge 1 commit into
Conversation
TimurRakhmatullin86
force-pushed
the
fix/kafka-test-connection-oauth
branch
2 times, most recently
from
July 19, 2026 17:23
c1cfff0 to
d6e80e6
Compare
test_connection built its config from the raw connection extra (plus, more recently, dotted-path callback resolution), but did not inject the managed OAuth token callback that get_conn adds for Google Managed Kafka and Amazon MSK IAM connections. As a result, "Test Connection" in the UI failed for those managed connections even though the hook itself authenticates and connects correctly. Extract the configuration-building logic shared with get_conn into a _build_config helper and have both get_conn and test_connection use it, so the UI test exercises exactly the same configuration (resolved callbacks plus the managed OAuth token callback) as a real connection. Signed-off-by: Timur Rakhmatullin <174210871+TimurRakhmatullin86@users.noreply.github.com>
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.
Problem
KafkaBaseHook.test_connection()builds itsAdminClientfrom the raw connectionconfiguration and (since the recent callback-resolution change) resolves dotted-path
callbacks — but it never injects the managed OAuth token callback that
get_connaddsfor Google Managed Service for Apache Kafka and Amazon MSK IAM connections. As a result,
"Test Connection" in the UI fails for those managed connections even though the hook
itself authenticates and connects correctly — the test path never gets the
oauth_cbtoken callback.
Fix
The configuration-building logic shared with
get_conn(bootstrap validation, dotted-pathcallback resolution, and the managed OAuth token injection for Google Managed Kafka /
Amazon MSK IAM) is extracted into a
_build_config()helper that bothget_connandtest_connectionuse. The UI test now exercises exactly the same configuration as a realconnection, so managed connections test successfully.
get_connbehaviour is unchanged (apure extraction).
Tests
test_test_connection_injects_managed_kafka_oauthasserts the managedoauth_cbispresent in the config passed to
AdminClientfromtest_connection.test_connectionunit tests now use a concrete non-managed broker address(
localhost:9092) instead of aMagicMock, sincetest_connectionnow builds the fullruntime config and a mock host would spuriously match the managed-Kafka path.
providers/apache/kafka/tests/unit/apache/kafka/hooks/test_base.pysuite passes(23/23);
ruff checkandruff format --checkare clean.