Description
When calling luigi.run() with an invalid argument type (int), the function fails deep inside argparse with TypeError: 'int' object is not iterable. This is confusing to users and indicates a lack of input validation at the luigi.run() level.
Steps to Reproduce
Minimal reproducible test:
import luigi
def test_run_with_invalid_args(self):
"""Test run() with invalid arguments fails naturally"""
luigi.run(123)
Expected behavior:
luigi.run() should validate that the input args is an iterable and raise a meaningful TypeError or ValueError such as:TypeError: luigi.run() expects a list or tuple of command-line arguments, got int.
Alternatively, the documentation should explicitly state the requirement for args to be iterable.
Actual behavior:
The input is passed to argparse without validation, leading to a confusing TypeError from inside the standard library, which obscures the root cause.
the traceback is:
___________________ LuigiTestCase.test_run_with_invalid_args ___________________
self = <test_run_tttmp.LuigiTestCase testMethod=test_run_with_invalid_args>
def test_run_with_invalid_args(self):
"""Test run() with invalid arguments fails naturally"""
> luigi.run(123)
test/test_run_tttmp.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
luigi/interface.py:200: in run
luigi_run_result = _run(*args, **kwargs)
luigi/interface.py:216: in _run
with CmdlineParser.global_instance(cmdline_args) as cp:
/root/anaconda3/envs/luigi_new/lib/python3.10/contextlib.py:135: in __enter__
return next(self.gen)
luigi/cmdline_parser.py:52: in global_instance
new_value = CmdlineParser(cmdline_args)
luigi/cmdline_parser.py:63: in __init__
known_args, _ = self._build_parser().parse_known_args(args=cmdline_args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = ArgumentParser(prog='__main__.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=False)
args = 123, namespace = None
def parse_known_args(self, args=None, namespace=None):
if args is None:
# args default to the system args
args = _sys.argv[1:]
else:
# make sure that args are mutable
> args = list(args)
E TypeError: 'int' object is not iterable
/root/anaconda3/envs/luigi_new/lib/python3.10/argparse.py:1845: TypeError
Reproduces How Often: Always
Versions:
-
Luigi: master
-
Python: 3.10.16
-
pytest: 8.3.5
-
Platform: Linux
Description
When calling
luigi.run()with an invalid argument type (int), the function fails deep insideargparsewithTypeError: 'int' object is not iterable. This is confusing to users and indicates a lack of input validation at theluigi.run()level.Steps to Reproduce
Minimal reproducible test:
Expected behavior:
luigi.run()should validate that the inputargsis an iterable and raise a meaningfulTypeErrororValueErrorsuch as:TypeError: luigi.run() expects a list or tuple of command-line arguments, got int.Alternatively, the documentation should explicitly state the requirement for
argsto be iterable.Actual behavior:
The input is passed to
argparsewithout validation, leading to a confusingTypeErrorfrom inside the standard library, which obscures the root cause.the traceback is:
Reproduces How Often: Always
Versions:
Luigi: master
Python: 3.10.16
pytest: 8.3.5
Platform: Linux