uranusjr commented on a change in pull request #19034:
URL: https://github.com/apache/airflow/pull/19034#discussion_r731414520



##########
File path: airflow/models/param.py
##########
@@ -38,37 +48,44 @@ class Param:
     :type schema: dict
     """
 
-    def __init__(self, default: Any = None, description: str = None, **kwargs):
-        self.default = default
+    __NO_VALUE_SENTINEL = NoValueSentinel()
+
+    def __init__(self, default: Any = __NO_VALUE_SENTINEL, description: str = 
None, **kwargs):
+        self.value = default
         self.description = description
         self.schema = kwargs.pop('schema') if 'schema' in kwargs else kwargs
 
-        # If default is not None, then validate it once, may raise ValueError
-        if default:
+        # If we have a value, validate it once. May raise ValueError.
+        if self.has_value:
             try:
-                jsonschema.validate(self.default, self.schema, 
format_checker=FormatChecker())
+                jsonschema.validate(self.value, self.schema, 
format_checker=FormatChecker())
             except ValidationError as err:
                 raise ValueError(err)
 
-    def resolve(self, value: Optional[Any] = None, suppress_exception: bool = 
False) -> Any:
+    def resolve(self, value: Optional[Any] = __NO_VALUE_SENTINEL, 
suppress_exception: bool = False) -> Any:
         """
         Runs the validations and returns the Param's final value.
-        May raise ValueError on failed validations.
+        May raise ValueError on failed validations, or AirflowException
+        if no value is passed and no value already exists.
 
         :param value: The value to be updated for the Param
         :type value: Optional[Any]
         :param suppress_exception: To raise an exception or not when the 
validations fails.
             If true and validations fails, the return value would be None.
         :type suppress_exception: bool
         """
+        final_val = value if value != self.__NO_VALUE_SENTINEL else self.value
+        if isinstance(final_val, NoValueSentinel):
+            if suppress_exception:
+                return None
+            raise AirflowException("No value passed and Param has no default 
value")

Review comment:
       `TypeError` is usually used for "argument needed but missing" situations
   
   ```pycon
   >>> open()
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
   TypeError: open() missing required argument 'file' (pos 1)
   ```
   
   so that could be appropriate?




-- 
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-unsubscr...@airflow.apache.org

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


Reply via email to