BasPH commented on code in PR #27540:
URL: https://github.com/apache/airflow/pull/27540#discussion_r1025100952


##########
docs/apache-airflow/concepts/taskflow.rst:
##########
@@ -81,6 +81,49 @@ To use logging from your task functions, simply import and 
use Python's logging
 
 Every logging line created this way will be recorded in the task log.
 
+Passing Arbitrary Objects As Parameters
+---------------------------------------
+
+.. versionadded:: 2.5.0
+
+As mentioned TaskFlow uses XCom to pass variables to each task. This requires 
that variables that are used as parameters
+to tasks need to be able to be serialized. Airflow out of the box supports all 
built-in types (like int or str) and it
+supports objects that are decorated with ``@dataclass`` or ``@attr.define``, 
but it will need some help if you want to
+pass custom objects or if you want to control serialization yourself. To do so 
add the ``serialize()`` method to your
+class and the staticmethod ``deserialize(data: dict, version: int)`` to your 
class. Like so:
+
+.. code-block:: python
+
+    from typing import ClassVar
+
+
+    class MyCustom:
+        version: ClassVar[int] = 1
+
+        def __init__(self, x):
+            self.x = x
+
+        def serialize(self) -> dict:
+            return dict({"x": self.x})
+
+        @staticmethod
+        def deserialize(data: dict, version: int):
+            if version > 1:
+                raise TypeError(f"version > {MyCustom.version}")
+            return MyCustom(data["x"])

Review Comment:
   Could you demonstrate a taskflow task using the `MyCustom` class in the 
example?



##########
docs/apache-airflow/concepts/taskflow.rst:
##########
@@ -81,6 +81,49 @@ To use logging from your task functions, simply import and 
use Python's logging
 
 Every logging line created this way will be recorded in the task log.
 
+Passing Arbitrary Objects As Parameters
+---------------------------------------
+
+.. versionadded:: 2.5.0
+
+As mentioned TaskFlow uses XCom to pass variables to each task. This requires 
that variables that are used as parameters
+to tasks need to be able to be serialized. Airflow out of the box supports all 
built-in types (like int or str) and it
+supports objects that are decorated with ``@dataclass`` or ``@attr.define``, 
but it will need some help if you want to
+pass custom objects or if you want to control serialization yourself. To do so 
add the ``serialize()`` method to your
+class and the staticmethod ``deserialize(data: dict, version: int)`` to your 
class. Like so:

Review Comment:
   ```suggestion
   TaskFlow uses XCom to pass variables to each task. This requires variables 
that are used as arguments
   to tasks to be able to be serialized. Airflow out of the box supports all 
built-in types (like int or str) and it
   supports objects that are decorated with ``@dataclass`` or ``@attr.define``, 
but it will need some help if you want to pass custom objects, or if you want 
to control serialization yourself. To do so, implement the ``serialize()`` 
method and ``deserialize(data: dict, version: int)`` staticmethod in your 
class. Like so:
   ```



##########
docs/apache-airflow/concepts/taskflow.rst:
##########
@@ -81,6 +81,49 @@ To use logging from your task functions, simply import and 
use Python's logging
 
 Every logging line created this way will be recorded in the task log.
 
+Passing Arbitrary Objects As Parameters

Review Comment:
   ```suggestion
   Passing Arbitrary Objects As Arguments
   ```



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