Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed default XCom deserialization. #14827

Merged
merged 3 commits into from Apr 20, 2021
Merged

Conversation

suiting-young
Copy link
Contributor

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.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

@@ -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):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those exceptions came from Python2 json.loads, have been replaced by JSONDecodeError (as below) in Python3.

Comment on lines -255 to -260
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."
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is meaningless here, as user can do nothing with values already existing in database.

# As 'enable_xcom_pickling' changed default from True to False,
# pickled (old) and JSON (new) are both existing.
pass
return pickle.loads(result.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

        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)

@github-actions
Copy link

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.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Mar 18, 2021
@kaxil kaxil merged commit 21c8f15 into apache:master Apr 20, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 20, 2021

Awesome work, congrats on your first merged pull request!

@suiting-young suiting-young deleted the xcom-pickle branch August 12, 2021 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full tests needed We need to run full set of tests for this PR to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants