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 2021/03/16 12:50:20 UTC

[GitHub] [airflow] kaxil commented on a change in pull request #14827: Fixed default XCom deserialization.

kaxil commented on a change in pull request #14827:
URL: https://github.com/apache/airflow/pull/14827#discussion_r595137577



##########
File path: airflow/models/xcom.py
##########
@@ -233,32 +227,25 @@ def serialize_value(value: Any):
             return json.dumps(value).encode('UTF-8')
         except (ValueError, TypeError):
             log.error(
-                "Could not serialize the XCom value into JSON. "
-                "If you are using pickles instead of JSON "
-                "for XCom, then you need to enable pickle "
-                "support for XCom in your airflow config."
+                "Could not serialize the XCom value into JSON."
+                " If you are using pickles instead of JSON for XCom,"
+                " then you need to enable pickle support for XCom"
+                " in your airflow config."
             )
             raise
 
     @staticmethod
     def deserialize_value(result: "XCom") -> Any:
         """Deserialize XCom value from str or pickle object"""
-        enable_pickling = conf.getboolean('core', 'enable_xcom_pickling')
-        if enable_pickling:
+        if not conf.getboolean('core', 'enable_xcom_pickling'):
             try:
-                return pickle.loads(result.value)
-            except pickle.UnpicklingError:
                 return json.loads(result.value.decode('UTF-8'))
-        try:
-            return json.loads(result.value.decode('UTF-8'))
-        except JSONDecodeError:
-            log.error(
-                "Could not deserialize the XCom value from JSON. "
-                "If you are using pickles instead of JSON "
-                "for XCom, then you need to enable pickle "
-                "support for XCom in your airflow config."
-            )
-            raise
+            except JSONDecodeError:
+                # For backward-compatibility.
+                # As 'enable_xcom_pickling' changed default from True to False,
+                # pickled (old) and JSON (new) are both existing.
+                pass
+        return pickle.loads(result.value)

Review comment:
       So what happens here where some values in DB are JSON Serialized and `enable_xcom_pickling` is `True`.
   
   The previous code accounted for that, this code does not




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org