amoghrajesh commented on code in PR #54102:
URL: https://github.com/apache/airflow/pull/54102#discussion_r2253235142


##########
airflow-core/src/airflow/example_dags/example_dag_decorator.py:
##########
@@ -22,13 +22,21 @@
 
 import httpx
 import pendulum
-
+import ipaddress
 from airflow.providers.standard.operators.bash import BashOperator
 from airflow.sdk import BaseOperator, dag, task
 
 if TYPE_CHECKING:
     from airflow.sdk import Context
 
+def is_ip(address: str) -> bool:
+    """Check if the provided address is a valid IP address (supports IPv4 and 
IPv6)."""
+    try:
+        # Try to convert the address to an IP address (supports both IPv4 and 
IPv6)
+        ipaddress.ip_address(address)
+        return True
+    except ValueError:
+        return False

Review Comment:
   Maybe try:
   ```
   raise AirflowException(f"Invalid IP address: '{external_ip}'.")
   ```



##########
airflow-core/src/airflow/example_dags/example_dag_decorator.py:
##########
@@ -22,13 +22,21 @@
 
 import httpx
 import pendulum
-
+import ipaddress
 from airflow.providers.standard.operators.bash import BashOperator
 from airflow.sdk import BaseOperator, dag, task
 
 if TYPE_CHECKING:
     from airflow.sdk import Context
 
+def is_ip(address: str) -> bool:
+    """Check if the provided address is a valid IP address (supports IPv4 and 
IPv6)."""
+    try:
+        # Try to convert the address to an IP address (supports both IPv4 and 
IPv6)
+        ipaddress.ip_address(address)
+        return True
+    except ValueError:
+        return False

Review Comment:
   UX wise and my personal take on this: for an invalid IP, there will be a 
silent failure and no real way for user to know that it is a bad practice being 
followed. I would rather that we raise this exception so that the task fails 
and it's evident what went wrong.



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