suiting-young commented on a change in pull request #14827:
URL: https://github.com/apache/airflow/pull/14827#discussion_r595815678
##########
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:
Isn't it `pickle` deprecated (*as in 1.10.x*) any more?
I'm trying to fix the **default** path that user haven't specify
`enable_xcom_pickling` in `airflow.cfg`.
That the value changed from `True` (_implicit, and then old_) to `False`
(_new_) silently.
If `pickle` is still the first class option, I'd like to implement a
bi-direction fallback.
```py
if conf.getboolean('core', 'enable_xcom_pickling'):
try:
return pickle.loads(result.value)
except pickle.UnpicklingError:
return json.loads(result.value.decode('UTF-8'))
else:
try:
return json.loads(result.value.decode('UTF-8'))
except JSONDecodeError:
return pickle.loads(result.value)
```
----------------------------------------------------------------
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:
[email protected]