fix: use bytes replacement in JobTask.dump for __main__ jobs - #3445
Open
Sanjays2402 wants to merge 1 commit into
Open
fix: use bytes replacement in JobTask.dump for __main__ jobs#3445Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
luigi.contrib.hadoop.JobTask.dump() rewrote the pickled module name with d.replace(b"(c__main__", "(c" + module_name), mixing a bytes pattern with a str replacement. Since pickle.dumps() returns bytes and sys.argv[0] is a str, this always raised TypeError: a bytes-like object is required, not 'str', so dumping a job defined in __main__ was impossible. The replacement is now encoded to bytes. Added a regression test that dumps a __main__-module job and fails with the reported TypeError without this fix. Closes spotify#3284
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
JobTask.dump()rewrote the pickled module name withd.replace(b"(c__main__", "(c" + module_name), mixing abytespattern with astrreplacement.Motivation and Context
pickle.dumps()returnsbytesandsys.argv[0]is astr, so this line always raisedTypeError: a bytes-like object is required, not 'str'and dumping a job defined in__main__was impossible. The replacement is now encoded to bytes.Closes #3284
Have you tested this? If so, how?
I have included a unit test. It fails with the reported
TypeErrorwithout the source change and passes with it;test/contrib/hadoop_test.pyis green (24 passed).