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 10:01:25 UTC
[GitHub] [airflow] suiting-young opened a new pull request #14827: Fixed default XCom deserialization.
suiting-young opened a new pull request #14827:
URL: https://github.com/apache/airflow/pull/14827
This is a fix for migrating with the default `enable_xcom_pickling` (*before & after*).
I.e. `pickle`-d (_old_) and `JSON` (_new_) data both existing in database.
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
----------------------------------------------------------------
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
[GitHub] [airflow] suiting-young commented on a change in pull request #14827: Fixed default XCom deserialization.
Posted by GitBox <gi...@apache.org>.
suiting-young commented on a change in pull request #14827:
URL: https://github.com/apache/airflow/pull/14827#discussion_r595022187
##########
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."
- )
Review comment:
This message is meaningless here, as user can do nothing with values already existing in database.
----------------------------------------------------------------
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
[GitHub] [airflow] kaxil commented on a change in pull request #14827: Fixed default XCom deserialization.
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #14827: Fixed default XCom deserialization.
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #14827:
URL: https://github.com/apache/airflow/pull/14827#issuecomment-823536901
Awesome work, congrats on your first merged pull request!
--
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
[GitHub] [airflow] suiting-young commented on a change in pull request #14827: Fixed default XCom deserialization.
Posted by GitBox <gi...@apache.org>.
suiting-young commented on a change in pull request #14827:
URL: https://github.com/apache/airflow/pull/14827#discussion_r595021082
##########
File path: airflow/models/xcom.py
##########
@@ -62,13 +62,7 @@ def init_on_load(self):
Called by the ORM after the instance has been loaded from the DB or otherwise reconstituted
i.e automatically deserialize Xcom value when loading from DB.
"""
- try:
- self.value = self.orm_deserialize_value()
- except (UnicodeEncodeError, ValueError):
Review comment:
Those exceptions came from Python2 `json.loads`, have been replaced by `JSONDecodeError` (_as below_) in Python3.
----------------------------------------------------------------
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
[GitHub] [airflow] kaxil merged pull request #14827: Fixed default XCom deserialization.
Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #14827:
URL: https://github.com/apache/airflow/pull/14827
--
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
[GitHub] [airflow] suiting-young commented on a change in pull request #14827: Fixed default XCom deserialization.
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [airflow] github-actions[bot] commented on pull request #14827: Fixed default XCom deserialization.
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14827:
URL: https://github.com/apache/airflow/pull/14827#issuecomment-802152172
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.
--
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