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

fix handling of \n in submission cli --add-file= option #6504

Merged
merged 4 commits into from
Dec 13, 2024

Conversation

grondo
Copy link
Contributor

@grondo grondo commented Dec 13, 2024

This PR fixes a small bug in the submission cli --add-file=[NAME=]DATA option. The option is documented to allow file data on the command line if DATA contains a \n. However, any \n passed on the command line ends up quoted, so this doesn't actually work:

$ flux submit --add-file=test='this is a test\n' hostname
flux-submit: ERROR: --add-file=test=this is a test\n: [Errno 2] No such file or directory: 'this is a test\\n'

This PR just unescapes in newlines in DATA so that newline detection works (and the newlines appear as newlines in the resulting fileref data).

Problem: A conditional in Jobspec.add_file() checks for a newline
in the data argument before checking that encoding is None, but
the check should only be done when encoding is None.

Reverse the order of the conditional so that newline is checked
only when encoding is None.
Problem: The code to handle --add-file arguments is all within a
condditional, but this code would be better moved to a function
for readability.

Add a function for handling `--add-file` args.
Copy link
Member

@garlick garlick left a comment

Choose a reason for hiding this comment

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

LGTM! Just one commit message nit.

@@ -969,7 +969,10 @@ def init_jobspec(self, args):

Copy link
Member

Choose a reason for hiding this comment

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

commit message: s/indicaates/indicates/

Problem: Documentation for the `--add-file=NAME=DATA` option indicates
that DATA will be treated as a path unless a newline appears in DATA.
However, the obvious doesn't work:

 --add-file=test='this is a test file\n'

because what Python actually gets is an escaped newline '\\n', so
test for '\n' in the string fail.

Convert any escaped newlines to actual newlines in
handle_add_file_arg() so that subsequent detection of newline works.
Problem: No test in the testsuite ensures that the submission cli
`--add-file` option properly detects '\n' in DATA and treats it like
file data instead of a path.

Add a test to t2710-python-cli-submit.t.
@grondo
Copy link
Contributor Author

grondo commented Dec 13, 2024

Thanks! Fixed that and will set MWP.

@mergify mergify bot merged commit 8f575da into flux-framework:master Dec 13, 2024
33 checks passed
@grondo grondo deleted the add-file-data branch December 13, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants