# Buggy code
def prepare_group(self, workspace, grouping, image_numbers):
    image_set_list = workspace.image_set_list
    pipeline = workspace.pipeline
    assert isinstance(pipeline, cpp.Pipeline)
    m = workspace.measurements
    assert isinstance(m, cpmeas.Measurements)
    if self.each_or_all != EA_EACH and len(image_numbers) > 0:
        title = "#%d: CorrectIlluminationCalculate for %s" % (
            self.module_num,
            self.image_name,
        )
        message = (
            "CorrectIlluminationCalculate is averaging %d images while "
            "preparing for run" % (len(image_numbers))
        )
        output_image_provider = CorrectIlluminationImageProvider(
            self.illumination_image_name.value, self
        )
        d = self.get_dictionary(image_set_list)[OUTPUT_IMAGE] = {}
        if self.each_or_all == EA_ALL_FIRST:
            for w in pipeline.run_group_with_yield(
                workspace, grouping, image_numbers, self, title, message
            ):
                image = w.image_set.get_image(self.image_name.value, cache=False)
                output_image_provider.add_image(image)
        output_image_provider.serialize(d)

    return True


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Applications/CellProfiler2.1.1_rc.app/Contents/Resources/lib/python2.7/cellprofiler/pipeline.py", line 2287, in prepare_group
File "/Applications/CellProfiler2.1.1_rc.app/Contents/Resources/lib/python2.7/cellprofiler/modules/correctilluminationcalculate.py", line 497, in prepare_group
File "/Applications/CellProfiler2.1.1_rc.app/Contents/Resources/lib/python2.7/cellprofiler/pipeline.py", line 2010, in run_group_with_yield
File "/Applications/CellProfiler2.1.1_rc.app/Contents/Resources/lib/python2.7/cellprofiler/modules/namesandtypes.py", line 1291, in run
File "/Applications/CellProfiler2.1.1_rc.app/Contents/Resources/lib/python2.7/cellprofiler/modules/namesandtypes.py", line 1328, in add_image_provider
File "/Applications/CellProfiler2.1.1_rc.app/Contents/Resources/lib/python2.7/cellprofiler/modules/namesandtypes.py", line 1361, in add_simple_image
File "/Applications/CellProfiler2.1.1_rc.app/Contents/Resources/lib/python2.7/cellprofiler/modules/namesandtypes.py", line 1388, in add_provider_measurements
AttributeError: 'MonochromeImageProvider' object has no attribute 'scale'

# Fixed code
def prepare_group(self, workspace, grouping, image_numbers):
    image_set_list = workspace.image_set_list
    pipeline = workspace.pipeline
    assert isinstance(pipeline, cpp.Pipeline)
    m = workspace.measurements
    assert isinstance(m, cpmeas.Measurements)
    if self.each_or_all != EA_EACH and len(image_numbers) > 0:
        title = "#%d: CorrectIlluminationCalculate for %s" % (
            self.module_num,
            self.image_name,
        )
        message = (
            "CorrectIlluminationCalculate is averaging %d images while "
            "preparing for run" % (len(image_numbers))
        )
        output_image_provider = CorrectIlluminationImageProvider(
            self.illumination_image_name.value, self
        )
        d = self.get_dictionary(image_set_list)[OUTPUT_IMAGE] = {}
        if self.each_or_all == EA_ALL_FIRST:
            #
            # Find the module that provides the image we need
            #
            md = workspace.pipeline.get_provider_dictionary(self.image_name.group, self)
            src_module, src_setting = md[self.image_name.value][-1]
            modules = list(pipeline.modules())
            idx = modules.index(src_module)
            last_module = modules[idx + 1]
            for w in pipeline.run_group_with_yield(
                workspace, grouping, image_numbers, last_module, title, message
            ):
                image = w.image_set.get_image(self.image_name.value, cache=False)
                output_image_provider.add_image(image)
                w.image_set.clear_cache()
        output_image_provider.serialize(d)

    return True