gurudesh/pytracebugs huggingface dataset:
# Buggy code
def reset_status(self):
    """Reset self._new_tool_ids and self._removed_tool_ids once
    all operations that need to know about new tools have finished running."""
    self._new_tool_ids = set()
    self._removed_tool_ids = set()


# Traceback (KeyError)
galaxy.tools.toolbox.base INFO 2018-08-09 10:57:04,513 Parsing the tool configuration /private/var/folders/df/6xqpqpcd7h73b6jpx9t6cwhw0000gn/T/tmpicezz6xb/tool_conf.xml
galaxy.tools.toolbox.base ERROR 2018-08-09 10:57:04,519 Error reading tool from path: /Users/mvandenb/src/tools-iuc/tools/fastp/fastp.xml
Traceback (most recent call last):
File "/private/var/folders/df/6xqpqpcd7h73b6jpx9t6cwhw0000gn/T/tmpicezz6xb/galaxy-dev/lib/galaxy/tools/toolbox/base.py", line 567, in _load_tool_tag_set
tool = self.load_tool(concrete_path, use_cached=False)
File "/private/var/folders/df/6xqpqpcd7h73b6jpx9t6cwhw0000gn/T/tmpicezz6xb/galaxy-dev/lib/galaxy/tools/toolbox/base.py", line 751, in load_tool
tool = self.create_tool(config_file=config_file, repository_id=repository_id, guid=guid, **kwds)
File "/private/var/folders/df/6xqpqpcd7h73b6jpx9t6cwhw0000gn/T/tmpicezz6xb/galaxy-dev/lib/galaxy/tools/__init__.py", line 270, in create_tool
raise e
KeyError: 'adapter_trimming_options'

# Fixed code
def reset_status(self):
    """
    Reset tracking of new and newly disabled tools.
    """
    self._new_tool_ids = set()
    self._removed_tool_ids = set()
    self._removed_tools_by_path = {}
# Buggy code
def to_dict(self, view="collection", value_mapper=None, app=None):
    as_dict = super(ToolOutput, self).to_dict(view=view, value_mapper=value_mapper)
    format = self.format
    if format and format != "input" and app:
        edam_format = app.datatypes_registry.edam_formats.get(self.format)
        as_dict["edam_format"] = edam_format
        edam_data = app.datatypes_registry.edam_data.get(self.format)
        as_dict["edam_data"] = edam_data
    return as_dict


# Traceback (bioblend.ConnectionError)
gi.tools.show_tool(tool_id, io_details = True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/path/to/bioblend/galaxy/tools/__init__.py", line 98, in show_tool
return self._get(id=tool_id, params=params)
File "/path/to/bioblend/galaxy/client.py", line 136, in _get
status_code=r.status_code)
bioblend.ConnectionError: GET: error 500: b'{"err_msg": "Uncaught exception in exposed API method:", "err_code": 0}', 0 attempts left: {"err_msg": "Uncaught exception in exposed API method:", "err_code": 0}

# Fixed code
def to_dict(self, view="collection", value_mapper=None, app=None):
    as_dict = super(ToolOutput, self).to_dict(
        view=view, value_mapper=value_mapper, app=app
    )
    format = self.format
    if format and format != "input" and app:
        edam_format = app.datatypes_registry.edam_formats.get(self.format)
        as_dict["edam_format"] = edam_format
        edam_data = app.datatypes_registry.edam_data.get(self.format)
        as_dict["edam_data"] = edam_data
    return as_dict
# Buggy code
def __link_file_check(self):
    """outputs_to_working_directory breaks library uploads where data is
    linked.  This method is a hack that solves that problem, but is
    specific to the upload tool and relies on an injected job param.  This
    method should be removed ASAP and replaced with some properly generic
    and stateful way of determining link-only datasets. -nate
    """
    job = self.get_job()
    param_dict = job.get_param_values(self.app)
    return (
        self.tool.id == "upload1"
        and param_dict.get("link_data_only", None) == "link_to_files"
    )


# Traceback (AttributeError)
galaxy.jobs.handler WARNING 2018-01-31 15:36:15,704 (78691) Tool 'motifgen-fasta_1' removed from tool config, unable to recover job
galaxy.jobs DEBUG 2018-01-31 15:36:15,705 (78691) Working directory for job is: /tools/galaxy_ratschlab/database/job_working_directory/078/78691
Traceback (most recent call last):
File "/tools/galaxy_ratschlab/lib/galaxy/webapps/galaxy/buildapp.py", line 58, in paste_app_factory
app = galaxy.app.UniverseApplication(global_conf=global_conf, **kwargs)
File "/tools/galaxy_ratschlab/lib/galaxy/app.py", line 190, in __init__
self.job_manager.start()
File "/tools/galaxy_ratschlab/lib/galaxy/jobs/manager.py", line 33, in start
self.job_handler.start()
File "/tools/galaxy_ratschlab/lib/galaxy/jobs/handler.py", line 40, in start
self.job_queue.start()
File "/tools/galaxy_ratschlab/lib/galaxy/jobs/handler.py", line 85, in start
self.__check_jobs_at_startup()
File "/tools/galaxy_ratschlab/lib/galaxy/jobs/handler.py", line 140, in __check_jobs_at_startup
self.job_wrapper(job).fail('This tool was disabled before the job completed.  Please contact your Galaxy administrator.')
File "/tools/galaxy_ratschlab/lib/galaxy/jobs/__init__.py", line 993, in fail
if outputs_to_working_directory and not self.__link_file_check():
File "/tools/galaxy_ratschlab/lib/galaxy/jobs/__init__.py", line 1747, in __link_file_check
param_dict = job.get_param_values(self.app)
File "/tools/galaxy_ratschlab/lib/galaxy/model/__init__.py", line 702, in get_param_values
param_dict = tool.params_from_strings(param_dict, app, ignore_errors=ignore_errors)
AttributeError: 'NoneType' object has no attribute 'params_from_strings'`

# Fixed code
def __link_file_check(self):
    """outputs_to_working_directory breaks library uploads where data is
    linked.  This method is a hack that solves that problem, but is
    specific to the upload tool and relies on an injected job param.  This
    method should be removed ASAP and replaced with some properly generic
    and stateful way of determining link-only datasets. -nate
    """
    if self.tool:
        job = self.get_job()
        param_dict = job.get_param_values(self.app)
        return (
            self.tool.id == "upload1"
            and param_dict.get("link_data_only", None) == "link_to_files"
        )
    else:
        # The tool is unavailable, we try to move the outputs.
        return False
# Buggy code
def pause(self, job=None, message=None):
    if job is None:
        job = self.get_job()
    if message is None:
        message = "Execution of this dataset's job is paused"
    if job.state == job.states.NEW:
        for dataset_assoc in job.output_datasets + job.output_library_datasets:
            dataset_assoc.dataset.dataset.state = (
                dataset_assoc.dataset.dataset.states.PAUSED
            )
            dataset_assoc.dataset.info = message
            self.sa_session.add(dataset_assoc.dataset)
        job.set_state(job.states.PAUSED)
        self.sa_session.add(job)


# Traceback (ValueError)
galaxy.jobs.handler DEBUG 2017-12-15 09:04:34,777 (3332) Dispatching to slurm runner
galaxy.jobs DEBUG 2017-12-15 09:04:34,808 (3332) Persisting job destination (destination id: cluster16c40)
galaxy.jobs.runners DEBUG 2017-12-15 09:04:34,815 Job [3332] queued (37.893 ms)
galaxy.jobs.handler INFO 2017-12-15 09:04:34,822 (3332) Job dispatched
galaxy.jobs.runners ERROR 2017-12-15 09:04:34,874 (3332) Failure preparing job
Traceback (most recent call last):
File "/galaxy/lib/galaxy/jobs/runners/__init__.py", line 170, in prepare_job
job_wrapper.prepare()
File "/galaxy/lib/galaxy/jobs/__init__.py", line 878, in prepare
tool_evaluator.set_compute_environment(compute_environment, get_special=get_special)
File "/galaxy/lib/galaxy/tools/evaluation.py", line 73, in set_compute_environment
visit_input_values(self.tool.inputs, incoming, validate_inputs)
File "/galaxy/lib/galaxy/tools/parameters/__init__.py", line 106, in visit_input_values
visit_input_values(input.cases[values['__current_case__']].inputs, values, callback, new_name_prefix, label_prefix, parent_prefix=name_prefix, **payload)
File "/galaxy/lib/galaxy/tools/parameters/__init__.py", line 112, in visit_input_values
callback_helper(input, input_values, name_prefix, label_prefix, parent_prefix=parent_prefix, context=context)
File "/galaxy/lib/galaxy/tools/parameters/__init__.py", line 77, in callback_helper
new_value = callback(**args)
File "/galaxy/lib/galaxy/tools/evaluation.py", line 71, in validate_inputs
value = input.from_json(value, request_context, context)
File "/galaxy/lib/galaxy/tools/parameters/basic.py", line 1676, in from_json
raise ValueError("The previously selected dataset has entered an unusable state")
ValueError: The previously selected dataset has entered an unusable state

# Fixed code
def pause(self, job=None, message=None):
    if job is None:
        job = self.get_job()
    if message is None:
        message = "Execution of this dataset's job is paused"
    if job.state == job.states.NEW:
        for dataset_assoc in job.output_datasets + job.output_library_datasets:
            dataset_assoc.dataset.dataset.state = (
                dataset_assoc.dataset.dataset.states.PAUSED
            )
            dataset_assoc.dataset.info = message
            self.sa_session.add(dataset_assoc.dataset)
        log.debug("Pausing Job '%d', %s", job.id, message)
        job.set_state(job.states.PAUSED)
        self.sa_session.add(job)
# Buggy code
def get_data_outputs(self):
    outputs = []
    if hasattr(self.subworkflow, "workflow_outputs"):
        for workflow_output in self.subworkflow.workflow_outputs:
            output_step = workflow_output.workflow_step
            label = workflow_output.label
            if label is None:
                label = "%s:%s" % (output_step.order_index, workflow_output.output_name)
            output = dict(
                name=label,
                label=label,
                extensions=["input"],  # TODO
            )
            outputs.append(output)
    return outputs


# Traceback (Exception)
Traceback (most recent call last):
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 82, in __invoke
outputs = invoker.invoke()
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 160, in invoke
jobs = self._invoke_step( step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 230, in _invoke_step
jobs = step.module.execute( self.trans, self.progress, self.workflow_invocation, step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/modules.py", line 435, in execute
subworkflow_invoker = progress.subworkflow_invoker( trans, step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 353, in subworkflow_invoker
subworkflow_progress = self.subworkflow_progress(step)
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 381, in subworkflow_progress
is_data=is_data,
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 305, in replacement_for_connection
raise Exception( message )
Exception: Workflow evaluation problem - failed to find output_name 1:out_file1 in step_outputs {None: <galaxy.model.HistoryDatasetAssociation object at 0x7f323f703890>}

# Fixed code
def get_data_outputs(self):
    outputs = []
    if hasattr(self.subworkflow, "workflow_outputs"):
        for workflow_output in self.subworkflow.workflow_outputs:
            if workflow_output.workflow_step.type in {
                "data_input",
                "data_collection_input",
            }:
                # It is just confusing to display the input data as output data in subworkflows
                continue
            output_step = workflow_output.workflow_step
            label = workflow_output.label
            if not label:
                label = "%s:%s" % (output_step.order_index, workflow_output.output_name)
            output = dict(
                name=label,
                label=label,
                extensions=["input"],  # TODO
            )
            outputs.append(output)
    return outputs
# Buggy code
def execute(self, trans, progress, invocation, step):
    """Execute the given workflow step in the given workflow invocation.
    Use the supplied workflow progress object to track outputs, find
    inputs, etc...
    """
    subworkflow_invoker = progress.subworkflow_invoker(trans, step)
    subworkflow_invoker.invoke()
    subworkflow = subworkflow_invoker.workflow
    subworkflow_progress = subworkflow_invoker.progress
    outputs = {}
    for workflow_output in subworkflow.workflow_outputs:
        workflow_output_label = workflow_output.label
        replacement = subworkflow_progress.get_replacement_workflow_output(
            workflow_output
        )
        outputs[workflow_output_label] = replacement
    progress.set_step_outputs(step, outputs)
    return None


# Traceback (Exception)
Traceback (most recent call last):
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 82, in __invoke
outputs = invoker.invoke()
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 160, in invoke
jobs = self._invoke_step( step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 230, in _invoke_step
jobs = step.module.execute( self.trans, self.progress, self.workflow_invocation, step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/modules.py", line 435, in execute
subworkflow_invoker = progress.subworkflow_invoker( trans, step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 353, in subworkflow_invoker
subworkflow_progress = self.subworkflow_progress(step)
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 381, in subworkflow_progress
is_data=is_data,
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 305, in replacement_for_connection
raise Exception( message )
Exception: Workflow evaluation problem - failed to find output_name 1:out_file1 in step_outputs {None: <galaxy.model.HistoryDatasetAssociation object at 0x7f323f703890>}

# Fixed code
def execute(self, trans, progress, invocation, step):
    """Execute the given workflow step in the given workflow invocation.
    Use the supplied workflow progress object to track outputs, find
    inputs, etc...
    """
    subworkflow_invoker = progress.subworkflow_invoker(trans, step)
    subworkflow_invoker.invoke()
    subworkflow = subworkflow_invoker.workflow
    subworkflow_progress = subworkflow_invoker.progress
    outputs = {}
    for workflow_output in subworkflow.workflow_outputs:
        workflow_output_label = workflow_output.label or "%s:%s" % (
            step.order_index,
            workflow_output.output_name,
        )
        replacement = subworkflow_progress.get_replacement_workflow_output(
            workflow_output
        )
        outputs[workflow_output_label] = replacement
    progress.set_step_outputs(step, outputs)
    return None
# Buggy code
def get_filter_set(self, connections=None):
    filter_set = []
    if connections:
        for oc in connections:
            for ic in oc.input_step.module.get_data_inputs():
                if "extensions" in ic and ic["name"] == oc.input_name:
                    filter_set += ic["extensions"]
    if not filter_set:
        filter_set = ["data"]
    return ", ".join(filter_set)


# Traceback (Exception)
Traceback (most recent call last):
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 82, in __invoke
outputs = invoker.invoke()
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 160, in invoke
jobs = self._invoke_step( step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 230, in _invoke_step
jobs = step.module.execute( self.trans, self.progress, self.workflow_invocation, step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/modules.py", line 435, in execute
subworkflow_invoker = progress.subworkflow_invoker( trans, step )
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 353, in subworkflow_invoker
subworkflow_progress = self.subworkflow_progress(step)
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 381, in subworkflow_progress
is_data=is_data,
File "/home/eteri/GalaxyProject/galaxy/lib/galaxy/workflow/run.py", line 305, in replacement_for_connection
raise Exception( message )
Exception: Workflow evaluation problem - failed to find output_name 1:out_file1 in step_outputs {None: <galaxy.model.HistoryDatasetAssociation object at 0x7f323f703890>}

# Fixed code
def get_filter_set(self, connections=None):
    filter_set = []
    if connections:
        for oc in connections:
            for ic in oc.input_step.module.get_data_inputs():
                if (
                    "extensions" in ic
                    and ic["extensions"] != "input"
                    and ic["name"] == oc.input_name
                ):
                    filter_set += ic["extensions"]
    if not filter_set:
        filter_set = ["data"]
    return ", ".join(filter_set)
# Buggy code
def reload_data_managers(app, **kwargs):
    from galaxy.tools.data_manager.manager import DataManagers

    log.debug("Executing data managers reload on '%s'", app.config.server_name)
    app._configure_tool_data_tables(from_shed_config=False)
    reload_tool_data_tables(app)
    reload_count = app.data_managers._reload_count
    app.data_managers = DataManagers(app, conf_watchers=app.data_managers.conf_watchers)
    app.data_managers._reload_count = reload_count + 1


# Traceback (DetachedInstanceError)
galaxy.web.framework.decorators ERROR 2017-04-08 10:22:00,380 Uncaught exception in exposed API method:
Traceback (most recent call last):
File "/var/galaxy/galaxy/lib/galaxy/web/framework/decorators.py", line 282, in decorator
rval = func( self, trans, *args, **kwargs )
File "/var/galaxy/galaxy/lib/galaxy/webapps/galaxy/api/tools.py", line 98, in build
return tool.to_json(trans, kwd.get('inputs', kwd))
File "/var/galaxy/galaxy/lib/galaxy/tools/__init__.py", line 1874, in to_json
tools = self.app.toolbox.get_loaded_tools_by_lineage( self.id )
File "/var/galaxy/galaxy/lib/galaxy/tools/toolbox/base.py", line 492, in get_loaded_tools_by_lineage
tool_lineage = self._lineage_map.get( tool_id )
File "/var/galaxy/galaxy/lib/galaxy/tools/toolbox/lineages/factory.py", line 38, in get
lineage = ToolShedLineage.from_tool_id( self.app, tool_id )
File "/var/galaxy/galaxy/lib/galaxy/tools/toolbox/lineages/tool_shed.py", line 70, in from_tool_id
return ToolShedLineage( app, tool_version )
File "/var/galaxy/galaxy/lib/galaxy/tools/toolbox/lineages/tool_shed.py", line 53, in __init__
self.tool_version_id = tool_version.id
File "/var/galaxy/galaxy/.venv/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 237, in __get__
return self.impl.get(instance_state(instance), dict_)
File "/var/galaxy/galaxy/.venv/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 578, in get
value = state._load_expired(state, passive)
File "/var/galaxy/galaxy/.venv/local/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 474, in _load_expired
self.manager.deferred_scalar_loader(self, toload)
File "/var/galaxy/galaxy/.venv/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 610, in load_scalar_attributes
(state_str(state)))
DetachedInstanceError: Instance <ToolVersion at 0x7f20d07ef390> is not bound to a Session; attribute refresh operation cannot proceed

# Fixed code
def reload_data_managers(app, **kwargs):
    from galaxy.tools.data_manager.manager import DataManagers
    from galaxy.tools.toolbox.lineages.tool_shed import ToolVersionCache

    log.debug("Executing data managers reload on '%s'", app.config.server_name)
    app._configure_tool_data_tables(from_shed_config=False)
    reload_tool_data_tables(app)
    reload_count = app.data_managers._reload_count
    app.data_managers = DataManagers(app, conf_watchers=app.data_managers.conf_watchers)
    app.data_managers._reload_count = reload_count + 1
    app.tool_version_cache = ToolVersionCache(app)
# Buggy code
def __init__(self, job_wrapper, job_destination):
    self.runner_state_handled = False
    self.job_wrapper = job_wrapper
    self.job_destination = job_destination


# Traceback (AttributeError)
galaxy.jobs.runners ERROR 2017-03-22 11:53:04,424 (1778) Unhandled exception calling queue_job
Traceback (most recent call last):
File "galaxy/lib/galaxy/jobs/runners/__init__.py", line 104, in run_next
method(arg)
File "galaxy/lib/galaxy/jobs/runners/local.py", line 133, in queue_job
self._fail_job_local(job_wrapper, "Unable to finish job")
File "galaxy/lib/galaxy/jobs/runners/local.py", line 173, in _fail_job_local
self.fail_job(job_state, exception=True)
File "galaxy/lib/galaxy/jobs/runners/__init__.py", line 381, in fail_job
job_state.cleanup()
AttributeError: 'JobState' object has no attribute 'cleanup'

# Fixed code
def __init__(self, job_wrapper, job_destination):
    self.runner_state_handled = False
    self.job_wrapper = job_wrapper
    self.job_destination = job_destination

    self.cleanup_file_attributes = [
        "job_file",
        "output_file",
        "error_file",
        "exit_code_file",
    ]
# Buggy code
def __init__(
    self,
    files_dir=None,
    job_wrapper=None,
    job_id=None,
    job_file=None,
    output_file=None,
    error_file=None,
    exit_code_file=None,
    job_name=None,
    job_destination=None,
):
    super(AsynchronousJobState, self).__init__(job_wrapper, job_destination)
    self.old_state = None
    self._running = False
    self.check_count = 0
    self.start_time = None

    # job_id is the DRM's job id, not the Galaxy job id
    self.job_id = job_id

    self.job_file = job_file
    self.output_file = output_file
    self.error_file = error_file
    self.exit_code_file = exit_code_file
    self.job_name = job_name

    self.set_defaults(files_dir)

    self.cleanup_file_attributes = [
        "job_file",
        "output_file",
        "error_file",
        "exit_code_file",
    ]


# Traceback (AttributeError)
galaxy.jobs.runners ERROR 2017-03-22 11:53:04,424 (1778) Unhandled exception calling queue_job
Traceback (most recent call last):
File "galaxy/lib/galaxy/jobs/runners/__init__.py", line 104, in run_next
method(arg)
File "galaxy/lib/galaxy/jobs/runners/local.py", line 133, in queue_job
self._fail_job_local(job_wrapper, "Unable to finish job")
File "galaxy/lib/galaxy/jobs/runners/local.py", line 173, in _fail_job_local
self.fail_job(job_state, exception=True)
File "galaxy/lib/galaxy/jobs/runners/__init__.py", line 381, in fail_job
job_state.cleanup()
AttributeError: 'JobState' object has no attribute 'cleanup'

# Fixed code
def __init__(
    self,
    files_dir=None,
    job_wrapper=None,
    job_id=None,
    job_file=None,
    output_file=None,
    error_file=None,
    exit_code_file=None,
    job_name=None,
    job_destination=None,
):
    super(AsynchronousJobState, self).__init__(job_wrapper, job_destination)
    self.old_state = None
    self._running = False
    self.check_count = 0
    self.start_time = None

    # job_id is the DRM's job id, not the Galaxy job id
    self.job_id = job_id

    self.job_file = job_file
    self.output_file = output_file
    self.error_file = error_file
    self.exit_code_file = exit_code_file
    self.job_name = job_name

    self.set_defaults(files_dir)
# Buggy code
def cleanup(self):
    for file in [
        getattr(self, a) for a in self.cleanup_file_attributes if hasattr(self, a)
    ]:
        try:
            os.unlink(file)
        except Exception as e:
            log.debug(
                "(%s/%s) Unable to cleanup %s: %s"
                % (self.job_wrapper.get_id_tag(), self.job_id, file, str(e))
            )


# Traceback (AttributeError)
galaxy.jobs.runners ERROR 2017-03-22 11:53:04,424 (1778) Unhandled exception calling queue_job
Traceback (most recent call last):
File "galaxy/lib/galaxy/jobs/runners/__init__.py", line 104, in run_next
method(arg)
File "galaxy/lib/galaxy/jobs/runners/local.py", line 133, in queue_job
self._fail_job_local(job_wrapper, "Unable to finish job")
File "galaxy/lib/galaxy/jobs/runners/local.py", line 173, in _fail_job_local
self.fail_job(job_state, exception=True)
File "galaxy/lib/galaxy/jobs/runners/__init__.py", line 381, in fail_job
job_state.cleanup()
AttributeError: 'JobState' object has no attribute 'cleanup'

# Fixed code
def cleanup(self):
    for file in [
        getattr(self, a) for a in self.cleanup_file_attributes if hasattr(self, a)
    ]:
        try:
            os.unlink(file)
        except Exception as e:
            # TODO: Move this prefix stuff to a method so we don't have dispatch on attributes we may or may
            # not have.
            if not hasattr(self, "job_id"):
                prefix = "(%s)" % self.job_wrapper.get_id_tag()
            else:
                prefix = "(%s/%s)" % (self.job_wrapper.get_id_tag(), self.job_id)
            log.debug("%s Unable to cleanup %s: %s" % (prefix, file, str(e)))
# Buggy code
def start(self):
    if not self._active:
        self._active = True
        self.thread.start()


# Traceback (AssertionError)
$ . .venv/bin/activate
(.venv)$ pip install watchdog
(.venv)$ tox -e py27-unit
...
======================================================================
FAIL: tools.test_watcher.test_tool_conf_watcher
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/galaxy/.venv/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/opt/galaxy/test/unit/tools/test_watcher.py", line 44, in test_tool_conf_watcher
wait_for_reload(lambda: callback.called)
File "/opt/galaxy/test/unit/tools/test_watcher.py", line 56, in wait_for_reload
assert reloaded
AssertionError

----------------------------------------------------------------------
Ran 787 tests in 73.355s

FAILED (SKIP=2, failures=1)

# Fixed code
def start(self):
    if not self._active:
        self._active = True
        register_postfork_function(self.thread.start)
# Buggy code
def monitor(self, path):
    mod_time = None
    if os.path.exists(path):
        mod_time = time.ctime(os.path.getmtime(path))
    with self._lock:
        self.paths[path] = mod_time


# Traceback (AssertionError)
$ . .venv/bin/activate
(.venv)$ pip install watchdog
(.venv)$ tox -e py27-unit
...
======================================================================
FAIL: tools.test_watcher.test_tool_conf_watcher
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/galaxy/.venv/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/opt/galaxy/test/unit/tools/test_watcher.py", line 44, in test_tool_conf_watcher
wait_for_reload(lambda: callback.called)
File "/opt/galaxy/test/unit/tools/test_watcher.py", line 56, in wait_for_reload
assert reloaded
AssertionError

----------------------------------------------------------------------
Ran 787 tests in 73.355s

FAILED (SKIP=2, failures=1)

# Fixed code
def monitor(self, path):
    mod_time = None
    if os.path.exists(path):
        mod_time = time.ctime(os.path.getmtime(path))
    with self._lock:
        self.paths[path] = mod_time
    self.start()
# Buggy code
def encode_dict_ids(self, a_dict, kind=None):
    """
    Encode all ids in dictionary. Ids are identified by (a) an 'id' key or
    (b) a key that ends with '_id'
    """
    for key, val in a_dict.items():
        if key == "id" or key.endswith("_id"):
            a_dict[key] = self.encode_id(val, kind=kind)

    return a_dict


# Traceback (RunToolException)
ERROR: Convert BIOM ( biom_convert ) > Test-1
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/tmp_EztYh/galaxy-dev/test/functional/test_toolbox.py", line 299, in test_tool
self.do_it( td )
File "/tmp/tmp_EztYh/galaxy-dev/test/functional/test_toolbox.py", line 60, in do_it
raise e
RunToolException: Error creating a job for these tool inputs - Attempted to encode None id

# Fixed code
def encode_dict_ids(self, a_dict, kind=None, skip_startswith=None):
    """
    Encode all ids in dictionary. Ids are identified by (a) an 'id' key or
    (b) a key that ends with '_id'
    """
    for key, val in a_dict.items():
        if (
            key == "id"
            or key.endswith("_id")
            and (skip_startswith is None or not key.startswith(skip_startswith))
        ):
            a_dict[key] = self.encode_id(val, kind=kind)

    return a_dict
# Buggy code
def logits(self, inputs, target=None, training=None):
    if training:
        return self.decoder_obj._logits_training(
            inputs, target=tf.cast(target, dtype=tf.int32), training=training
        )
    else:
        return inputs


# Traceback (AttributeError)
2020-10-19 03:06:47.001119: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "train.py", line 78, in <module>
train(args)
File "train.py", line 41, in train
ludwig_model.save_savedmodel(args.model_dir)
File "/usr/local/lib/python3.6/dist-packages/ludwig/api.py", line 1445, in save_savedmodel
self.model.save_savedmodel(save_path)
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 82, in save_savedmodel
keras_model = self.get_connected_model(training=False)
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 77, in get_connected_model
inputs = inputs or self.get_model_inputs(training)
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 63, in get_model_inputs
self.input_features.items()
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 62, in <dictcomp>
for input_feature_name, input_feature in
File "/usr/local/lib/python3.6/dist-packages/ludwig/features/base_feature.py", line 70, in create_input
return tf.keras.Input(shape=self.get_input_shape(),
File "/usr/local/lib/python3.6/dist-packages/ludwig/features/set_feature.py", line 127, in get_input_shape
return len(self.vocab),
AttributeError: 'SetInputFeature' object has no attribute 'vocab'

# Fixed code
def logits(self, inputs, target=None, training=None):
    if training and target is not None:
        return self.decoder_obj._logits_training(
            inputs, target=tf.cast(target, dtype=tf.int32), training=training
        )
    else:
        return inputs
# Buggy code
def __init__(self, feature):
    super().__init__(feature)

    self.height = 0
    self.width = 0
    self.num_channels = 0

    self.in_memory = True
    self.data_hdf5_fp = ""

    self.encoder = "stacked_cnn"

    encoder_parameters = self.overwrite_defaults(feature)

    self.encoder_obj = self.get_image_encoder(encoder_parameters)


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/andrey/.venvs/ludwig-learn/bin/ludwig", line 11, in <module>
sys.exit(main())
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 86, in main
CLI()
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 64, in __init__
getattr(self, args.command)()
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 73, in predict
predict.cli(sys.argv[2:])
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 379, in cli
full_predict(**vars(args))
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 104, in full_predict
debug
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 173, in predict
gpu_fraction=gpu_fraction
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/models/model.py", line 1182, in predict
only_predictions=only_predictions
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/models/model.py", line 756, in batch_evaluation
is_training=is_training
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
run_metadata_ptr)
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1128, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1,) for Tensor 'image_path/image_path:0', which has shape '(?, 100, 100, 3)'

# Fixed code
def __init__(self, feature):
    super().__init__(feature)

    self.height = 0
    self.width = 0
    self.num_channels = 0

    self.in_memory = True

    self.encoder = "stacked_cnn"

    encoder_parameters = self.overwrite_defaults(feature)

    self.encoder_obj = self.get_image_encoder(encoder_parameters)
# Buggy code
def update_model_definition_with_metadata(
    input_feature, feature_metadata, *args, **kwargs
):
    for dim in ["height", "width", "num_channels"]:
        input_feature[dim] = feature_metadata["preprocessing"][dim]
    input_feature["data_hdf5_fp"] = kwargs["model_definition"]["data_hdf5_fp"]


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/andrey/.venvs/ludwig-learn/bin/ludwig", line 11, in <module>
sys.exit(main())
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 86, in main
CLI()
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 64, in __init__
getattr(self, args.command)()
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 73, in predict
predict.cli(sys.argv[2:])
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 379, in cli
full_predict(**vars(args))
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 104, in full_predict
debug
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 173, in predict
gpu_fraction=gpu_fraction
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/models/model.py", line 1182, in predict
only_predictions=only_predictions
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/models/model.py", line 756, in batch_evaluation
is_training=is_training
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
run_metadata_ptr)
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1128, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1,) for Tensor 'image_path/image_path:0', which has shape '(?, 100, 100, 3)'

# Fixed code
def update_model_definition_with_metadata(
    input_feature, feature_metadata, *args, **kwargs
):
    for dim in ["height", "width", "num_channels"]:
        input_feature[dim] = feature_metadata["preprocessing"][dim]
# Buggy code
def save_csv(data_fp, data):
    writer = csv.writer(open(data_fp, "w"))
    for row in data:
        if not isinstance(row, collections.Iterable) or isinstance(row, str):
            row = [row]
        writer.writerow(row)


# Traceback (UnicodeEncodeError)
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\Scripts\ludwig-script.py", line 11, in <module>
load_entry_point('ludwig==0.1.0', 'console_scripts', 'ludwig')()
File "c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages\ludwig\cli.py", line 86, in main
CLI()
File "c:\users\xxxi\appdata\local\programs\python\python36\lib\site-packages\ludwig\cli.py", line 64, in __init__
getattr(self, args.command)()
File "c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages\ludwig\cli.py", line 73, in predict
predict.cli(sys.argv[2:])
File "c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages\ludwig\predict.py", line 379, in cli
full_predict(**vars(args))
File "c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages\ludwig\predict.py", line 120, in full_predict
save_prediction_outputs(postprocessed_output, experiment_dir_name)
File "c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages\ludwig\predict.py", line 210, in save_prediction_outputs
save_csv(csv_filename.format(output_field, output_type), values)
File "c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages\ludwig\utils\data_utils.py", line 60, in save_csv
writer.writerow(row)
File "c:\users\xxx\appdata\local\programs\python\python36\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u264b' in position 0: character maps to <undefined>

# Fixed code
def save_csv(data_fp, data):
    with open(data_fp, "w", encoding="utf-8") as csv_file:
        writer = csv.writer(csv_file)
        for row in data:
            if not isinstance(row, collections.Iterable) or isinstance(row, str):
                row = [row]
            writer.writerow(row)
# Buggy code
def replace_text_feature_level(model_definition, datasets):
    for feature in (
        model_definition["input_features"] + model_definition["output_features"]
    ):
        if feature["type"] == TEXT:
            for dataset in datasets:
                dataset[feature["name"]] = dataset[
                    "{}_{}".format(feature["name"], feature["level"])
                ]
                for level in ("word", "char"):
                    del dataset["{}_{}".format(feature["name"], level)]


# Traceback (KeyError)
Traceback (most recent call last):
File "/Users/user/.virtualenvs/ml/bin/ludwig", line 10, in <module>
sys.exit(main())
File "/Users/user/.virtualenvs/ml/lib/python3.6/site-packages/ludwig/cli.py", line 86, in main
CLI()
File "/Users/user/.virtualenvs/ml/lib/python3.6/site-packages/ludwig/cli.py", line 64, in __init__
getattr(self, args.command)()
File "/Users/user/.virtualenvs/ml/lib/python3.6/site-packages/ludwig/cli.py", line 70, in train
train.cli(sys.argv[2:])
File "/Users/user/.virtualenvs/ml/lib/python3.6/site-packages/ludwig/train.py", line 663, in cli
full_train(**vars(args))
File "/Users/user/.virtualenvs/ml/lib/python3.6/site-packages/ludwig/train.py", line 224, in full_train
random_seed=random_seed
File "/Users/user/.virtualenvs/ml/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 562, in preprocess_for_training
[training_set, validation_set, test_set]
File "/Users/user/.virtualenvs/ml/lib/python3.6/site-packages/ludwig/data/preprocessing.py", line 777, in replace_text_feature_level
level)
KeyError: 'name_word'

# Fixed code
def replace_text_feature_level(model_definition, datasets):
    for feature in (
        model_definition["input_features"] + model_definition["output_features"]
    ):
        if feature["type"] == TEXT:
            for dataset in datasets:
                dataset[feature["name"]] = dataset[
                    "{}_{}".format(feature["name"], feature["level"])
                ]
                for level in ("word", "char"):
                    name_level = "{}_{}".format(feature["name"], level)
                    if name_level in dataset:
                        del dataset[name_level]
# Buggy code
def get(self, path: str) -> None:
    parts = path.split("/")
    component_name = parts[0]
    component_root = self._registry.get_component_path(component_name)
    if component_root is None:
        self.write(f"{path} not found")
        self.set_status(404)
        return

    filename = "/".join(parts[1:])
    abspath = os.path.join(component_root, filename)

    LOGGER.debug("ComponentRequestHandler: GET: %s -> %s", path, abspath)

    try:
        with open(abspath, "r") as file:
            contents = file.read()
    except OSError as e:
        self.write(f"{path} read error: {e}")
        self.set_status(404)
        return

    self.write(contents)
    self.set_header("Content-Type", self.get_content_type(abspath))

    self.set_extra_headers(path)


# Traceback (UnicodeDecodeError)
2021-01-15 15:36:40.902 Uncaught exception GET /component/streamlit_material.core.base.streamlit_material/static/media/roboto-latin-500-normal.020c97dc.woff2 (::1)
HTTPServerRequest(protocol='http', host='localhost:8501', method='GET', uri='/component/streamlit_material.core.base.streamlit_material/static/media/roboto-latin-500-normal.020c97dc.woff2', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/home/user/.pyenv/versions/3.8.6/envs/streamlit_components/lib/python3.8/site-packages/tornado/web.py", line 1702, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/home/user/.pyenv/versions/3.8.6/envs/streamlit_components/lib/python3.8/site-packages/streamlit/components/v1/components.py", line 324, in get
contents = file.read()
File "/home/user/.pyenv/versions/3.8.6/lib/python3.8/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8f in position 18: invalid start byte

# Fixed code
def get(self, path: str) -> None:
    parts = path.split("/")
    component_name = parts[0]
    component_root = self._registry.get_component_path(component_name)
    if component_root is None:
        self.write(f"{path} not found")
        self.set_status(404)
        return

    filename = "/".join(parts[1:])
    abspath = os.path.join(component_root, filename)

    LOGGER.debug("ComponentRequestHandler: GET: %s -> %s", path, abspath)

    try:
        with open(abspath, "r", encoding="utf-8") as file:
            contents = file.read()
    except (OSError, UnicodeDecodeError) as e:
        self.write(f"{path} read error: {e}")
        self.set_status(404)
        return

    self.write(contents)
    self.set_header("Content-Type", self.get_content_type(abspath))

    self.set_extra_headers(path)
# Buggy code
def reset(cls):
    """Reset credentials by removing file.

    This is used by `streamlit activate reset` in case a user wants
    to start over.
    """
    Credentials._singleton = None
    c = Credentials()
    try:
        os.remove(c._conf_file)
    except OSError as e:
        LOGGER.error("Error removing credentials file: %s" % e)


# Traceback (AttributeError)
Exception in thread ScriptRunner.scriptThread:
Traceback (most recent call last):
File "/Users/adrien/.pyenv/versions/3.6.5/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/Users/adrien/.pyenv/versions/3.6.5/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/Users/adrien/.pyenv/versions/3.6.5/envs/streamlit-pre-launch/lib/python3.6/site-packages/streamlit/ScriptRunner.py", line 147, in _process_request_queue
self._run_script(data)
File "/Users/adrien/.pyenv/versions/3.6.5/envs/streamlit-pre-launch/lib/python3.6/site-packages/streamlit/ScriptRunner.py", line 238, in _run_script
self.on_event.send(ScriptRunnerEvent.SCRIPT_STARTED)
File "/Users/adrien/.pyenv/versions/3.6.5/envs/streamlit-pre-launch/lib/python3.6/site-packages/blinker/base.py", line 267, in send
for receiver in self.receivers_for(sender)]
File "/Users/adrien/.pyenv/versions/3.6.5/envs/streamlit-pre-launch/lib/python3.6/site-packages/blinker/base.py", line 267, in <listcomp>
for receiver in self.receivers_for(sender)]
File "/Users/adrien/.pyenv/versions/3.6.5/envs/streamlit-pre-launch/lib/python3.6/site-packages/streamlit/ReportSession.py", line 257, in _on_scriptrunner_event
self._maybe_enqueue_initialize_message()
File "/Users/adrien/.pyenv/versions/3.6.5/envs/streamlit-pre-launch/lib/python3.6/site-packages/streamlit/ReportSession.py", line 360, in _maybe_enqueue_initialize_message
imsg.user_info.email = Credentials.get_current().activation.email
AttributeError: 'NoneType' object has no attribute 'email'

# Fixed code
def reset(cls):
    """Reset credentials by removing file.

    This is used by `streamlit activate reset` in case a user wants
    to start over.
    """
    c = Credentials.get_current()
    c.activation = None

    try:
        os.remove(c._conf_file)
    except OSError as e:
        LOGGER.error("Error removing credentials file: %s" % e)
# Buggy code
def __init__(self, uri):
    self._uri = uri

    payload = {"op": "OPEN", "offset": 0}
    self._response = requests.get("http://" + self._uri, params=payload, stream=True)
    self._buf = b""


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-40-b63bd711d13c> in <module>
----> 1 smart_copy('./test_file.txt', 'webhdfs://XXXX@XXX.XXX.XXX.XXX:XXXXX/user/XXXX/smart_copy/test_file.txt')

<ipython-input-38-694f70cf0776> in smart_copy(source_file, sync_file)
3     '''
4     with open(source_file, 'rb') as source:
----> 5         with open(sync_file, 'wb') as sync:
6             for line in source:
7                 sync.write(line)

~/Github/tools/.venv/lib/python3.7/site-packages/smart_open/smart_open_lib.py in open(uri, mode, buffering, encoding, errors, newline, closefd, opener, ignore_ext, transport_params)
346     except KeyError:
347         binary_mode = mode
--> 348     binary, filename = _open_binary_stream(uri, binary_mode, transport_params)
349     if ignore_ext:
350         decompressed = binary

~/Github/tools/.venv/lib/python3.7/site-packages/smart_open/smart_open_lib.py in _open_binary_stream(uri, mode, transport_params)
560         elif parsed_uri.scheme == "webhdfs":
561             kw = _check_kwargs(smart_open_webhdfs.open, transport_params)
--> 562             return smart_open_webhdfs.open(parsed_uri.uri_path, mode, **kw), filename
563         elif parsed_uri.scheme.startswith('http'):
564             #

~/Github/tools/.venv/lib/python3.7/site-packages/smart_open/webhdfs.py in open(uri, mode, min_part_size)
40         return BufferedInputBase(uri)
41     elif mode == 'wb':
---> 42         return BufferedOutputBase(uri, min_part_size=min_part_size)
43     else:
44         raise NotImplementedError('webhdfs support for mode %r not implemented' % mode)

~/Github/tools/.venv/lib/python3.7/site-packages/smart_open/webhdfs.py in __init__(self, uri_path, min_part_size)
129                                      params=payload, allow_redirects=False)
130         if not init_response.status_code == httplib.TEMPORARY_REDIRECT:
--> 131             raise WebHdfsException(str(init_response.status_code) + "\n" + init_response.content)
132         uri = init_response.headers['location']
133         response = requests.put(uri, data="", headers={'content-type': 'application/octet-stream'})

TypeError: can only concatenate str (not "bytes") to str

# Fixed code
def __init__(self, uri):
    self._uri = uri

    payload = {"op": "OPEN", "offset": 0}
    self._response = requests.get(self._uri, params=payload, stream=True)
    if self._response.status_code != httplib.OK:
        raise WebHdfsException.from_response(self._response)
    self._buf = b""