BasPH commented on code in PR #27540:
URL: https://github.com/apache/airflow/pull/27540#discussion_r1025110283
##########
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:
Referring to https://github.com/apache/airflow/pull/26486 :-) ?
--
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]