Skip to content

fix: use bytes replacement in JobTask.dump for __main__ jobs - #3445

Open
Sanjays2402 wants to merge 1 commit into
spotify:masterfrom
Sanjays2402:fix/hadoop-dump-bytes-replace
Open

fix: use bytes replacement in JobTask.dump for __main__ jobs#3445
Sanjays2402 wants to merge 1 commit into
spotify:masterfrom
Sanjays2402:fix/hadoop-dump-bytes-replace

Conversation

@Sanjays2402

Copy link
Copy Markdown

Description

JobTask.dump() rewrote the pickled module name with d.replace(b"(c__main__", "(c" + module_name), mixing a bytes pattern with a str replacement.

Motivation and Context

pickle.dumps() returns bytes and sys.argv[0] is a str, so this line always raised TypeError: 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 TypeError without the source change and passes with it; test/contrib/hadoop_test.py is green (24 passed).

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
@Sanjays2402
Sanjays2402 requested review from a team and dlstadther as code owners July 25, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JobTask.dump raises TypeError when replacing bytes to string

1 participant