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 2022/09/13 15:30:53 UTC

[GitHub] [airflow] uranusjr opened a new pull request, #26369: Handle list when serializing expand_kwargs

uranusjr opened a new pull request, #26369:
URL: https://github.com/apache/airflow/pull/26369

   A type hint is also added to ensure we don't miss things like this in the future. Fix #26360.


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


[GitHub] [airflow] uranusjr commented on pull request #26369: Handle list when serializing expand_kwargs

Posted by GitBox <gi...@apache.org>.
uranusjr commented on PR #26369:
URL: https://github.com/apache/airflow/pull/26369#issuecomment-1245883832

   We can add a simple test to make sure the deserialisation part does not error, the value of that would be minimal but maybe still meaningful.


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


[GitHub] [airflow] uranusjr commented on a diff in pull request #26369: Handle list when serializing expand_kwargs

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #26369:
URL: https://github.com/apache/airflow/pull/26369#discussion_r969784530


##########
airflow/serialization/serialized_objects.py:
##########
@@ -215,13 +249,29 @@ class _ExpandInputRef(NamedTuple):
     """
 
     key: str
-    value: Union[_XComRef, Dict[str, Any]]
+    value: _ExpandInputSerializedValue
+
+    @classmethod
+    def validate_expand_input_value(cls, value: _ExpandInputOriginalValue) -> None:
+        """Validate we've covered all ``ExpandInput.value`` types.
+
+        This function does not actually do anything, but is called during
+        serialization so Mypy will *statically* check we have handled all
+        possible ExpandInput cases.
+        """
 
     def deref(self, dag: DAG) -> ExpandInput:
+        """De-reference into a concrete ExpandInput object.
+
+        If you add more cases here, be sure to update _ExpandInputOriginalValue
+        and _ExpandInputSerializedValue to match the logic.
+        """
         if isinstance(self.value, _XComRef):
             value: Any = self.value.deref(dag)
-        else:
+        elif isinstance(self.value, collections.abc.Mapping):
             value = {k: v.deref(dag) if isinstance(v, _XComRef) else v for k, v in self.value.items()}
+        else:
+            value = [v.deref(dag) if isinstance(v, _XComRef) else v for v in self.value]

Review Comment:
   This is the actual fix; the rest is infrastructure to ensure this kind of error is caught by Mypy in the future.



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


[GitHub] [airflow] uranusjr merged pull request #26369: Handle list when serializing expand_kwargs

Posted by GitBox <gi...@apache.org>.
uranusjr merged PR #26369:
URL: https://github.com/apache/airflow/pull/26369


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