MaksYermak commented on code in PR #47563:
URL: https://github.com/apache/airflow/pull/47563#discussion_r2000768944


##########
providers/apache/kafka/src/airflow/providers/apache/kafka/hooks/base.py:
##########
@@ -70,6 +69,15 @@ def get_conn(self) -> Any:
             and bootstrap_servers.find("cloud.goog") != -1
             and bootstrap_servers.find("managedkafka") != -1
         ):
+            try:
+                from airflow.providers.google.cloud.hooks.managed_kafka import 
ManagedKafkaHook
+            except ImportError:
+                from airflow.exceptions import 
AirflowOptionalProviderFeatureException
+
+                raise AirflowOptionalProviderFeatureException(
+                    "Failed to import ManagedKafkaHook. For using this 
functionality google provider version "
+                    ">= 14.1.0 should be pre-installed."
+                )

Review Comment:
   @eladkal sorry, but I think I was unclear with my explanation. My solution 
accepts your criteria and imports Google provider and raises Exceptions only in 
cases when users try to use the Kafka cluster on Google infrastructure. In all 
other cases these operators will work as before. Checking whether it's Cluster 
on Google infrastructure or not here:
   ```
   bootstrap_servers = config.get("bootstrap.servers")
           if (
               bootstrap_servers
               and bootstrap_servers.find("cloud.goog") != -1
               and bootstrap_servers.find("managedkafka") != -1
           ):
   ``` 
   and link to the code 
https://github.com/apache/airflow/blob/main/providers/apache/kafka/src/airflow/providers/apache/kafka/hooks/base.py#L67C9-L72C11



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to