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

subprocess.run throws exception when input and stdin are passed as kwargs #79067

Closed
aecant mannequin opened this issue Oct 3, 2018 · 11 comments
Closed

subprocess.run throws exception when input and stdin are passed as kwargs #79067

aecant mannequin opened this issue Oct 3, 2018 · 11 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@aecant
Copy link
Mannequin

aecant mannequin commented Oct 3, 2018

BPO 34886
Nosy @gpshead, @serhiy-storchaka, @MojoVampire, @miss-islington, @remilapeyre, @aecant
PRs
  • bpo-34886: Fix subprocess.run handling of exclusive arguments #11727
  • bpo-34886: Fix subprocess.run handling of exclusive arguments #11727
  • bpo-34886: Fix subprocess.run handling of exclusive arguments #11727
  • [3.8] bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727) #13916
  • [3.7] bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727) #13917
  • Files
  • subprocess_run_bug.py: Minimal working example
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/gpshead'
    closed_at = <Date 2019-06-11.04:55:33.824>
    created_at = <Date 2018-10-03.18:50:38.319>
    labels = ['3.7', '3.8', 'type-bug', 'library', '3.9']
    title = 'subprocess.run throws exception when input and stdin are passed as kwargs'
    updated_at = <Date 2019-06-11.04:55:33.810>
    user = 'https://github.com/aecant'

    bugs.python.org fields:

    activity = <Date 2019-06-11.04:55:33.810>
    actor = 'gregory.p.smith'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2019-06-11.04:55:33.824>
    closer = 'gregory.p.smith'
    components = ['Library (Lib)']
    creation = <Date 2018-10-03.18:50:38.319>
    creator = 'aecant'
    dependencies = []
    files = ['47847']
    hgrepos = []
    issue_num = 34886
    keywords = ['patch', 'patch', 'patch']
    message_count = 11.0
    messages = ['327002', '327003', '327004', '327008', '327009', '327011', '334728', '345042', '345046', '345049', '345179']
    nosy_count = 6.0
    nosy_names = ['gregory.p.smith', 'serhiy.storchaka', 'josh.r', 'miss-islington', 'remi.lapeyre', 'aecant']
    pr_nums = ['11727', '11727', '11727', '13916', '13917']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34886'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @aecant
    Copy link
    Mannequin Author

    aecant mannequin commented Oct 3, 2018

    If input and stdin parameters are passed as keyword arguments to subprocess.run, an exception is thrown even if input and stdin are both None.

    The exception is ValueError: stdin and input arguments may not both be used.

    I attach a minimal working example of the bug

    @aecant aecant mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 3, 2018
    @serhiy-storchaka
    Copy link
    Member

    What is wrong with this?

    @aecant
    Copy link
    Mannequin Author

    aecant mannequin commented Oct 3, 2018

    subprocess.run('ls', input=b'', stdin=None) # this is ok
    
    kwargs = {'input': b'', 'stdin': None}
    subprocess.run('ls', **kwargs) # this throws exception

    The two calls should have the same behaviour, but one throws exception and the other doesn't. I think the exception shouldn't be thrown, because stdin is None.

    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Oct 3, 2018

    I just tried:

        subprocess.run('ls', input=b'', stdin=None)

    and I got the same ValueError as for passing using kwargs. Where did you get the idea subprocess.run('ls', input=b'', stdin=None) worked?

    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Oct 3, 2018

    The actual code receives input by name, but stdin is received in **kwargs. The test is just:

        if input is not None:
            if 'stdin' in kwargs:
                raise ValueError(...)
            kwargs['stdin'] = PIPE

    Perhaps just change `if 'stdin' in kwargs:` to:

        if kwargs.get('stdin') is not None:

    so it obeys the documented API (that says stdin defaults to None, and therefore passing stdin=None explicitly should be equivalent to not passing it at all)?

    @aecant
    Copy link
    Mannequin Author

    aecant mannequin commented Oct 3, 2018

    and I got the same ValueError as for passing using kwargs. Where did you get the idea subprocess.run('ls', input=b'', stdin=None) worked?

    Sorry, the example was wrong. Both calls have the same behaviour.

    so it obeys the documented API (that says stdin defaults to None, and therefore passing stdin=None explicitly should be equivalent to not passing it at all)?

    The actual problem is this. The fix you propose works for me.

    @remilapeyre
    Copy link
    Mannequin

    remilapeyre mannequin commented Feb 1, 2019

    I opened a PR with @josh.r proposed change.

    @gpshead
    Copy link
    Member

    gpshead commented Jun 8, 2019

    New changeset 8cc605a by Gregory P. Smith (Rémi Lapeyre) in branch 'master':
    bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)
    8cc605a

    @miss-islington
    Copy link
    Contributor

    New changeset 6324ac1 by Miss Islington (bot) in branch '3.8':
    bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)
    6324ac1

    @miss-islington
    Copy link
    Contributor

    New changeset 10b4fd9 by Miss Islington (bot) in branch '3.7':
    bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)
    10b4fd9

    @gpshead
    Copy link
    Member

    gpshead commented Jun 11, 2019

    thanks!

    @gpshead gpshead added 3.8 only security fixes 3.9 only security fixes labels Jun 11, 2019
    @gpshead gpshead closed this as completed Jun 11, 2019
    @gpshead gpshead self-assigned this Jun 11, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants