You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/08/12 21:22:14 UTC

[GitHub] [airflow] jedcunningham commented on a change in pull request #17578: Improve validation of Group id

jedcunningham commented on a change in pull request #17578:
URL: https://github.com/apache/airflow/pull/17578#discussion_r688087786



##########
File path: airflow/utils/helpers.py
##########
@@ -56,6 +57,21 @@ def validate_key(k: str, max_length: int = 250) -> bool:
         return True
 
 
+def validate_group_key(k: str, max_length: int = 200) -> bool:
+    """Validates value used as a group key."""
+    if not isinstance(k, str):
+        raise TypeError(f"The key has to be a string and is {type(k)}:{k}")
+    elif len(k) > max_length:
+        raise AirflowException(f"The key has to be less than {max_length} characters")
+    elif not GROUP_KEY_REGEX.match(k):
+        raise AirflowException(
+            "The key ({k}) has to be made of alphanumeric characters, dashes "
+            "and underscores exclusively".format(k=k)

Review comment:
       ```suggestion
               f"The key ({k}) has to be made of alphanumeric characters, dashes "
               "and underscores exclusively"
   ```

##########
File path: airflow/utils/helpers.py
##########
@@ -56,6 +57,21 @@ def validate_key(k: str, max_length: int = 250) -> bool:
         return True
 
 
+def validate_group_key(k: str, max_length: int = 200) -> bool:
+    """Validates value used as a group key."""
+    if not isinstance(k, str):
+        raise TypeError(f"The key has to be a string and is {type(k)}:{k}")
+    elif len(k) > max_length:
+        raise AirflowException(f"The key has to be less than {max_length} characters")
+    elif not GROUP_KEY_REGEX.match(k):
+        raise AirflowException(
+            "The key ({k}) has to be made of alphanumeric characters, dashes "
+            "and underscores exclusively".format(k=k)
+        )
+    else:
+        return True

Review comment:
       ```suggestion
       if len(k) > max_length:
           raise AirflowException(f"The key has to be less than {max_length} characters")
       if not GROUP_KEY_REGEX.match(k):
           raise AirflowException(
               "The key ({k}) has to be made of alphanumeric characters, dashes "
               "and underscores exclusively".format(k=k)
           )
   
       return True
   ```
   
   nit




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org