Skip to content

Commit

Permalink
bugfix: Make CmdlineParser available during execution summary (#2415)
Browse files Browse the repository at this point in the history
Previously you could get an error + stack-trace when luigi is evaluating the exit code.

closes #2411
  • Loading branch information
mcarlsen authored and Tarrasch committed May 7, 2018
1 parent 772b877 commit 5f15649
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
7 changes: 4 additions & 3 deletions luigi/retcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ def run_with_retcodes(argv):
logger.exception("Uncaught exception in luigi")
sys.exit(retcodes.unhandled_exception)

task_sets = luigi.execution_summary._summary_dict(worker)
root_task = luigi.execution_summary._root_task(worker)
non_empty_categories = {k: v for k, v in task_sets.items() if v}.keys()
with luigi.cmdline_parser.CmdlineParser.global_instance(argv):
task_sets = luigi.execution_summary._summary_dict(worker)
root_task = luigi.execution_summary._root_task(worker)
non_empty_categories = {k: v for k, v in task_sets.items() if v}.keys()

def has(status):
assert status in luigi.execution_summary._ORDERED_STATUSES
Expand Down
32 changes: 32 additions & 0 deletions test/cmdline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ def run(self):
raise ValueError()


class RequiredConfig(luigi.Config):
required_test_param = luigi.Parameter()


class TaskThatRequiresConfig(luigi.WrapperTask):
def requires(self):
if RequiredConfig().required_test_param == 'A':
return SubTaskThatFails()


class SubTaskThatFails(luigi.Task):
def complete(self):
return False

def run(self):
raise Exception()


class CmdlineTest(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -339,6 +357,20 @@ def test_stack_trace_has_no_inner(self):
self.assertFalse(stdout.find(b"run() got an unexpected keyword argument 'tracking_url_callback'") != -1)
self.assertFalse(stdout.find(b'During handling of the above exception, another exception occurred') != -1)

def test_cmd_line_params_are_available_for_execution_summary(self):
"""
Test that config parameters specified on the command line are available while generating the execution summary.
"""
returncode, stdout, stderr = self._run_cmdline([
'./bin/luigi', '--module', 'cmdline_test', 'TaskThatRequiresConfig', '--local-scheduler', '--no-lock'
'--RequiredConfig-required-test-param', 'A',
])
print(stdout)
print(stderr)

self.assertNotEquals(returncode, 1)
self.assertFalse(b'required_test_param' in stderr)


if __name__ == '__main__':
# Needed for one of the tests
Expand Down

0 comments on commit 5f15649

Please sign in to comment.