uranusjr commented on code in PR #73909:
URL: https://github.com/apache/airflow/pull/73909#discussion_r4610954141


##########
task-sdk/src/airflow/sdk/definitions/param.py:
##########
@@ -161,18 +161,50 @@ class ParamsDict(MutableMapping[str, Any]):
 
     All the keys are strictly string and values are converted into Param's 
object
     if they are not already. This class is to replace param's dictionary 
implicitly
-    and ideally not needed to be used directly.
+    and is only needed directly to declare ``presets``.
 
     :param dict_obj: A dict or dict like object to init ParamsDict
     :param suppress_exception: Flag to suppress value exceptions while 
initializing the ParamsDict
+    :param presets: named sets of param values offered in the trigger form, 
mapping a preset name
+        to the param values it applies, e.g. ``{"Nightly": {"batch_size": 512, 
"shuffle": True}}``.
+        A preset only needs to list the params it changes; the rest keep their 
defaults. Every key
+        must name a param in this ParamsDict and its value must satisfy that 
param's schema. Only
+        the presets of a Dag's params are used.
     """
 
     __version__: ClassVar[int] = 1
-    __slots__ = ["__dict", "suppress_exception"]
+    __slots__ = ["__dict", "presets", "suppress_exception"]
 
-    def __init__(self, dict_obj: Mapping[str, Any] | None = None, 
suppress_exception: bool = False):
+    def __init__(
+        self,
+        dict_obj: Mapping[str, Any] | None = None,
+        suppress_exception: bool = False,
+        *,
+        presets: dict[str, dict[str, Any]] | None = None,
+    ):
         self.__dict = {k: v if isinstance(v, Param) else Param(v) for k, v in 
(dict_obj or {}).items()}
         self.suppress_exception = suppress_exception
+        self.presets: dict[str, dict[str, Any]] = presets or {}

Review Comment:
   This is public and mutable, so a modification would skip validation. Some 
protection should be implemented if it’s intended to be public.



##########
task-sdk/src/airflow/sdk/definitions/param.py:
##########
@@ -161,18 +161,50 @@ class ParamsDict(MutableMapping[str, Any]):
 
     All the keys are strictly string and values are converted into Param's 
object
     if they are not already. This class is to replace param's dictionary 
implicitly
-    and ideally not needed to be used directly.
+    and is only needed directly to declare ``presets``.
 
     :param dict_obj: A dict or dict like object to init ParamsDict
     :param suppress_exception: Flag to suppress value exceptions while 
initializing the ParamsDict
+    :param presets: named sets of param values offered in the trigger form, 
mapping a preset name
+        to the param values it applies, e.g. ``{"Nightly": {"batch_size": 512, 
"shuffle": True}}``.
+        A preset only needs to list the params it changes; the rest keep their 
defaults. Every key
+        must name a param in this ParamsDict and its value must satisfy that 
param's schema. Only
+        the presets of a Dag's params are used.
     """
 
     __version__: ClassVar[int] = 1
-    __slots__ = ["__dict", "suppress_exception"]
+    __slots__ = ["__dict", "presets", "suppress_exception"]
 
-    def __init__(self, dict_obj: Mapping[str, Any] | None = None, 
suppress_exception: bool = False):
+    def __init__(
+        self,
+        dict_obj: Mapping[str, Any] | None = None,
+        suppress_exception: bool = False,
+        *,
+        presets: dict[str, dict[str, Any]] | None = None,
+    ):
         self.__dict = {k: v if isinstance(v, Param) else Param(v) for k, v in 
(dict_obj or {}).items()}
         self.suppress_exception = suppress_exception
+        self.presets: dict[str, dict[str, Any]] = presets or {}

Review Comment:
   Also, since ParamsDict support modification on the internal data, validation 
would need to be redone whenever that happens with `__setitem__` and 
`__delitem__`. `_convert_params` already does this, but it does not guard the 
object itself from being consistent.
   
   I kind of feel storing the presets on ParamsDict may be a wrong choice since 
it opens all these inconsistency questions. We might want to store them and do 
the entire validation elsewhere instead.



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