This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v3-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-1-test by this push:
     new ed902572aea [v3-1-test] update serializer document to reflect the 
latest change in codebase (#56269) (#56857)
ed902572aea is described below

commit ed902572aea73cc7c6c1ddcb1f0ca94d89ff0187
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sun Oct 19 19:46:02 2025 +0200

    [v3-1-test] update serializer document to reflect the latest change in 
codebase (#56269) (#56857)
    
    (cherry picked from commit c2bccf13b001ad4914e6dc27663a109eb0fb214f)
    
    Co-authored-by: Kevin Yang <[email protected]>
---
 .../docs/authoring-and-scheduling/serializers.rst  | 37 ++++++++++++----------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/airflow-core/docs/authoring-and-scheduling/serializers.rst 
b/airflow-core/docs/authoring-and-scheduling/serializers.rst
index 433485bb3b8..fb19a111d91 100644
--- a/airflow-core/docs/authoring-and-scheduling/serializers.rst
+++ b/airflow-core/docs/authoring-and-scheduling/serializers.rst
@@ -74,8 +74,7 @@ Airflow Object
 
         @staticmethod
         def deserialize(data: dict[str, Any], version: int):
-            f = Foo(a=data["a"])
-            f.b = data["b"]
+            f = Foo(a=data["a"], v=data["b"])
             return f
 
 
@@ -86,17 +85,18 @@ Registered
 
     from __future__ import annotations
 
-    from decimal import Decimal
     from typing import TYPE_CHECKING
 
     from airflow.utils.module_loading import qualname
 
     if TYPE_CHECKING:
+        import decimal
+
         from airflow.serialization.serde import U
 
 
     serializers = [
-        Decimal
+        "decimal.Decimal"
     ]  # this can be a type or a fully qualified str. Str can be used to 
prevent circular imports
     deserializers = serializers  # in some cases you might not have a 
deserializer (e.g. k8s pod)
 
@@ -105,25 +105,28 @@ Registered
 
     # the serializer expects output, classname, version, is_serialized?
     def serialize(o: object) -> tuple[U, str, int, bool]:
-        if isinstance(o, Decimal):
-            name = qualname(o)
-            _, _, exponent = o.as_tuple()
-            if exponent >= 0:  # No digits after the decimal point.
-                return int(o), name, __version__, True
-                # Technically lossy due to floating point errors, but the best 
we
-                # can do without implementing a custom encode function.
-            return float(o), name, __version__, True
+        from decimal import Decimal
 
-        return "", "", 0, False
+        if not isinstance(o, Decimal):
+            return "", "", 0, False
+        name = qualname(o)
+        _, _, exponent = o.as_tuple()
+        if isinstance(exponent, int) and exponent >= 0:  # No digits after the 
decimal point.
+            return int(o), name, __version__, True
+        # Technically lossy due to floating point errors, but the best we
+        # can do without implementing a custom encode function.
+        return float(o), name, __version__, True
 
 
     # the deserializer sanitizes the data for you, so you do not need to 
deserialize values yourself
-    def deserialize(classname: str, version: int, data: object) -> Decimal:
+    def deserialize(cls: type, version: int, data: object) -> Decimal:
+        from decimal import Decimal
+
         # always check version compatibility
         if version > __version__:
-            raise TypeError(f"serialized {version} of {classname} > 
{__version__}")
+            raise TypeError(f"serialized {version} of {qualname(cls)} > 
{__version__}")
 
-        if classname != qualname(Decimal):
-            raise TypeError(f"{classname} != {qualname(Decimal)}")
+        if cls is not Decimal:
+            raise TypeError(f"do not know how to deserialize {qualname(cls)}")
 
         return Decimal(str(data))

Reply via email to