# Buggy code
def get_printout(out, opts=None, **kwargs):
    """
    Return a printer function
    """
    if opts is None:
        opts = {}

    if "output" in opts:
        # new --out option
        out = opts["output"]

    if out == "text":
        out = "txt"
    elif out is None or out == "":
        out = "nested"
    if opts.get("progress", False):
        out = "progress"

    opts.update(kwargs)
    if "color" not in opts:

        def is_pipe():
            """
            Check if sys.stdout is a pipe or not
            """
            try:
                fileno = sys.stdout.fileno()
            except AttributeError:
                fileno = -1  # sys.stdout is StringIO or fake
            return not os.isatty(fileno)

        if opts.get("force_color", False):
            opts["color"] = True
        elif opts.get("no_color", False) or is_pipe() or salt.utils.is_windows():
            opts["color"] = False
        else:
            opts["color"] = True

    outputters = salt.loader.outputters(opts)
    if out not in outputters:
        # Since the grains outputter was removed we don't need to fire this
        # error when old minions are asking for it
        if out != "grains":
            log.error(
                "Invalid outputter {0} specified, fall back to nested".format(out)
            )
        return outputters["nested"]
    return outputters[out]


# Traceback (AttributeError)
# salt --out=highstate '*' state.highstate
[ERROR   ] Nested output failed:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 43, in try_printout
return get_printout('nested', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in _format_host
key=lambda k: data[k].get('__run_num__', 0)):
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in <lambda>
key=lambda k: data[k].get('__run_num__', 0)):
AttributeError: 'list' object has no attribute 'get'
[ERROR   ] Nested output failed:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 43, in try_printout
return get_printout('nested', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in _format_host
key=lambda k: data[k].get('__run_num__', 0)):
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in <lambda>
key=lambda k: data[k].get('__run_num__', 0)):
AttributeError: 'list' object has no attribute 'get'
[ERROR   ] Nested output failed:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 43, in try_printout
return get_printout('nested', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 137, in _format_host
schanged, ctext = _format_changes(ret['changes'])
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 421, in _format_changes
__opts__)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 164, in out_format
return try_printout(data, out, opts)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 46, in try_printout
return get_printout('raw', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in _format_host
key=lambda k: data[k].get('__run_num__', 0)):
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in <lambda>
key=lambda k: data[k].get('__run_num__', 0)):
AttributeError: 'list' object has no attribute 'get'
[ERROR   ] Nested output failed:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 43, in try_printout
return get_printout('nested', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in _format_host
key=lambda k: data[k].get('__run_num__', 0)):
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in <lambda>
key=lambda k: data[k].get('__run_num__', 0)):
AttributeError: 'list' object has no attribute 'get'
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
AttributeError: 'list' object has no attribute 'get'
Traceback (most recent call last):
File "/usr/bin/salt", line 10, in <module>
salt_main()
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 454, in salt_main
client.run()
File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 204, in run
self._output_ret(ret_, out)
File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 303, in _output_ret
salt.output.display_output(ret, out, self.config)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 86, in display_output
display_data = try_printout(data, out, opts)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 46, in try_printout
return get_printout('raw', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 137, in _format_host
schanged, ctext = _format_changes(ret['changes'])
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 421, in _format_changes
__opts__)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 164, in out_format
return try_printout(data, out, opts)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 46, in try_printout
return get_printout('raw', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in _format_host
key=lambda k: data[k].get('__run_num__', 0)):
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in <lambda>
key=lambda k: data[k].get('__run_num__', 0)):
AttributeError: 'list' object has no attribute 'get'
Traceback (most recent call last):
File "/usr/bin/salt", line 10, in <module>
salt_main()
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 454, in salt_main
client.run()
File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 204, in run
self._output_ret(ret_, out)
File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 303, in _output_ret
salt.output.display_output(ret, out, self.config)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 86, in display_output
display_data = try_printout(data, out, opts)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 46, in try_printout
return get_printout('raw', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 137, in _format_host
schanged, ctext = _format_changes(ret['changes'])
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 421, in _format_changes
__opts__)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 164, in out_format
return try_printout(data, out, opts)
File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 46, in try_printout
return get_printout('raw', opts)(data).rstrip()
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
return _format_host(host, hostdata)[0]
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in _format_host
key=lambda k: data[k].get('__run_num__', 0)):
File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 129, in <lambda>
key=lambda k: data[k].get('__run_num__', 0)):
AttributeError: 'list' object has no attribute 'get'

# Fixed code
def get_printout(out, opts=None, **kwargs):
    """
    Return a printer function
    """
    if opts is None:
        opts = {}

    if "output" in opts and opts["output"] != "highstate":
        # new --out option, but don't choke when using --out=highstate at CLI
        # See Issue #29796 for more information.
        out = opts["output"]

    if out == "text":
        out = "txt"
    elif out is None or out == "":
        out = "nested"
    if opts.get("progress", False):
        out = "progress"

    opts.update(kwargs)
    if "color" not in opts:

        def is_pipe():
            """
            Check if sys.stdout is a pipe or not
            """
            try:
                fileno = sys.stdout.fileno()
            except AttributeError:
                fileno = -1  # sys.stdout is StringIO or fake
            return not os.isatty(fileno)

        if opts.get("force_color", False):
            opts["color"] = True
        elif opts.get("no_color", False) or is_pipe() or salt.utils.is_windows():
            opts["color"] = False
        else:
            opts["color"] = True

    outputters = salt.loader.outputters(opts)
    if out not in outputters:
        # Since the grains outputter was removed we don't need to fire this
        # error when old minions are asking for it
        if out != "grains":
            log.error(
                "Invalid outputter {0} specified, fall back to nested".format(out)
            )
        return outputters["nested"]
    return outputters[out]