pankajastro commented on code in PR #72855:
URL: https://github.com/apache/airflow/pull/72855#discussion_r3982006762


##########
task-sdk/src/airflow/sdk/definitions/connection.py:
##########
@@ -220,7 +220,19 @@ def get_hook(self, *, hook_params=None):
         hook = ProvidersManagerTaskRuntime().hooks.get(self.conn_type, None)
 
         if hook is None:
-            raise AirflowException(f'Unknown hook type "{self.conn_type}"')
+            if not self.conn_type:
+                # A URI scheme cannot contain '_' (RFC 3986), so "foo_bar://h" 
parses with no
+                # scheme at all and leaves conn_type empty. Name that, instead 
of reporting an
+                # unknown hook type of "".
+                message = (
+                    f"Connection {self.conn_id!r} has no connection type, so 
no hook could be "
+                    "looked up. If it was defined as a URI, note that a URI 
scheme cannot "
+                    "contain '_' (RFC 3986) and such a URI parses with no 
scheme at all: use "
+                    "'-' in the URI instead, which is decoded back to '_' on 
read."
+                )
+            else:
+                message = f'Unknown hook type "{self.conn_type}"'

Review Comment:
   Same question as the airflow-core copy — should the hyphenated-`conn_type` 
case get the round-trip explanation here too, not just empty `conn_type`?
   
   ---
   Drafted-by: Claude Sonnet 5; reviewed by @pankajastro before posting



##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -393,7 +401,19 @@ def get_hook(self, *, hook_params=None):
         hook = ProvidersManager().hooks.get(self.conn_type, None)
 
         if hook is None:
-            raise AirflowException(f'Unknown hook type "{self.conn_type}"')
+            if not self.conn_type:
+                # A URI scheme cannot contain '_' (RFC 3986), so "foo_bar://h" 
parses with no
+                # scheme at all and leaves conn_type empty. Name that, instead 
of reporting an
+                # unknown hook type of "".
+                message = (
+                    f"Connection {self.conn_id!r} has no connection type, so 
no hook could be "
+                    "looked up. If it was defined as a URI, note that a URI 
scheme cannot "
+                    "contain '_' (RFC 3986) and such a URI parses with no 
scheme at all: use "
+                    "'-' in the URI instead, which is decoded back to '_' on 
read."
+                )
+            else:
+                message = f'Unknown hook type "{self.conn_type}"'

Review Comment:
   Is the empty-`conn_type` case the only one that reaches an unhelpful message 
here? A `Connection` with a hyphenated `conn_type` set directly (never 
round-tripped through `get_uri()`) hits this `else` and still gets the bare 
`Unknown hook type "google-cloud-platform"`, without the round-trip explanation 
this PR adds. Should this branch also cover `"-" in self.conn_type`?
   
   ---
   Drafted-by: Claude Sonnet 5; reviewed by @pankajastro before posting



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