materialsproject / fireworks

The Fireworks Workflow Management Repo.
https://materialsproject.github.io/fireworks
Other
351 stars 184 forks source link

Responding to confirmation prompt raises ValueError #446

Closed janosh closed 3 years ago

janosh commented 3 years ago

Responding "N" to lpad pause_wflows -s RUNNING confirmation prompt raises ValueError. There's no reason to raise as the program received one of the expected inputs.

lpad pause_wflows -s RUNNING
Are you sure? This will modify 12 entries. (Y/N)N

Traceback (most recent call last):
  File "miniconda3/envs/py38/bin/lpad", line 8, in <module>
    sys.exit(lpad())
  File "fireworks/scripts/lpad_run.py", line 1435, in lpad
    args.func(args)
  File "fireworks/scripts/lpad_run.py", line 532, in pause_wfs
    fw_ids = parse_helper(lp, args, wf_mode=True)
  File "fireworks/scripts/lpad_run.py", line 100, in parse_helper
    return pw_check(lp.get_wf_ids(query, sort=sort, limit=max), args, skip_pw)
  File "fireworks/scripts/lpad_run.py", line 58, in pw_check
    raise ValueError('Operation aborted by user.')

Suggested change:

def pw_check(ids, args, skip_pw=False):
    if len(ids) > PW_CHECK_NUM and not skip_pw:
        m_password = datetime.datetime.now().strftime('%Y-%m-%d')
        if not args.password:
            if input('Are you sure? This will modify {} entries. (Y/N)'.format(len(ids)))[0].upper() == 'Y':
                args.password = datetime.datetime.now().strftime('%Y-%m-%d')
            else:
-               raise ValueError('Operation aborted by user.')
+               print('Operation aborted by user.')
        if args.password != m_password:
            raise ValueError("Modifying more than {} entries requires setting the --password parameter! "
                             "(Today's date, e.g. 2012-02-25)".format(PW_CHECK_NUM))
    return ids