gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _serialize_payload(
    payload: dict, use_msgpack: Optional[bool] = False
) -> Union[bytes, str]:
    logging.debug(f"Serializing to msgpack: {use_msgpack}")
    if use_msgpack:
        return msgpack.dumps(payload, default=json_iso_dttm_ser, use_bin_type=True)
    else:
        return json.dumps(payload, default=json_iso_dttm_ser, ignore_nan=True)


# Traceback (RuntimeError)
Task sql_lab.get_sql_results[051acb0d-30a5-4dbe-b30e-5b16bc9d8545] raised unexpected: RuntimeError('Working outside of application context.\n\nThis typically means that you attempted to use functionality that needed\nto interface with the current application object in some way. To solve\nthis, set up an application context with app.app_context().  See the\ndocumentation for more information.',)
Traceback (most recent call last):
File "/Users/rob/work/incubator-superset/venv/lib/python3.6/site-packages/celery/app/trace.py", line 385, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/rob/work/incubator-superset/venv/lib/python3.6/site-packages/celery/app/trace.py", line 648, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/rob/work/incubator-superset/superset/sql_lab.py", line 154, in get_sql_results
with session_scope(not ctask.request.called_directly) as session:
File "/Users/rob/work/incubator-superset/venv/lib/python3.6/site-packages/contextlib2.py", line 79, in __enter__
return next(self.gen)
File "/Users/rob/work/incubator-superset/superset/sql_lab.py", line 117, in session_scope
app.config["SQLALCHEMY_DATABASE_URI"], poolclass=NullPool
File "/Users/rob/work/incubator-superset/venv/lib/python3.6/site-packages/werkzeug/local.py", line 348, in __getattr__
return getattr(self._get_current_object(), name)
File "/Users/rob/work/incubator-superset/venv/lib/python3.6/site-packages/werkzeug/local.py", line 307, in _get_current_object
return self.__local()
File "/Users/rob/work/incubator-superset/venv/lib/python3.6/site-packages/flask/globals.py", line 52, in _find_app
raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
to interface with the current application object in some way. To solve
this, set up an application context with app.app_context().  See the
documentation for more information.

# Fixed code
def _serialize_payload(
    payload: dict, use_msgpack: Optional[bool] = False
) -> Union[bytes, str]:
    logger.debug(f"Serializing to msgpack: {use_msgpack}")
    if use_msgpack:
        return msgpack.dumps(payload, default=json_iso_dttm_ser, use_bin_type=True)
    else:
        return json.dumps(payload, default=json_iso_dttm_ser, ignore_nan=True)
# Buggy code
def get_csv(self):
    df = self.get_df()
    include_index = not isinstance(df.index, pd.RangeIndex)
    return df.to_csv(index=include_index)


# Traceback (UnicodeEncodeError)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/flask_appbuilder/security/decorators.py", line 26, in wraps
return f(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/caravel/models.py", line 1164, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/caravel/views.py", line 515, in explore
payload = obj.get_csv()
File "/usr/local/lib/python2.7/dist-packages/caravel/viz.py", line 282, in get_csv
return df.to_csv(index=include_index)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 1343, in to_csv
formatter.save()
File "/usr/local/lib/python2.7/dist-packages/pandas/core/format.py", line 1550, in save
self._save()
File "/usr/local/lib/python2.7/dist-packages/pandas/core/format.py", line 1651, in _save
self._save_chunk(start_i, end_i)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/format.py", line 1677, in _save_chunk
lib.write_csv_rows(self.data, ix, self.nlevels, self.cols, self.writer)
File "pandas/lib.pyx", line 1078, in pandas.lib.write_csv_rows (pandas/lib.c:19848)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal not in range(128)

# Fixed code
def get_csv(self):
    df = self.get_df()
    include_index = not isinstance(df.index, pd.RangeIndex)
    return df.to_csv(index=include_index, encoding="utf-8")
# Buggy code
def night_mode(self, night_mode):
    """Switch on/off the speaker's night mode.

    :param night_mode: Enable or disable night mode
    :type night_mode: bool
    :raises NotSupportedException: If the device does not support
    night mode.
    """
    if not self.speaker_info:
        self.get_speaker_info()
    if "PLAYBAR" not in self.speaker_info["model_name"]:
        message = "This device does not support night mode"
        raise NotSupportedException(message)

    self.renderingControl.SetEQ(
        [("InstanceID", 0), ("EQType", "NightMode"), ("DesiredValue", int(night_mode))]
    )


# Traceback (soco.exceptions.NotSupportedException)
my_zone
SoCo("192.168.2.253")
my_zone.get_speaker_info()
{u'display_version': '9.1', u'player_icon': '/img/icon-S11.png', u'uid': 'RINCON_XYZ', u'software_version': '45.1-56150', u'mac_address': u'MA-CA-DD-RE-S-S', u'hardware_version': '1.14.1.11-1', u'model_number': 'S11', u'serial_number': 'MA-CA-DD-RE-S-S:1', u'zone_name': 'Family Room', u'model_name': 'Sonos Playbase'}
my_zone.night_mode = True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/soco/core.py", line 813, in night_mode
raise NotSupportedException(message)
soco.exceptions.NotSupportedException: This device does not support night mode
my_zone.dialog_mode = True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/soco/core.py", line 851, in dialog_mode
raise NotSupportedException(message)
soco.exceptions.NotSupportedException: This device does not support dialog mode

# Fixed code
def night_mode(self, night_mode):
    """Switch on/off the speaker's night mode.

    :param night_mode: Enable or disable night mode
    :type night_mode: bool
    :raises NotSupportedException: If the device does not support
    night mode.
    """
    if not self.is_soundbar:
        message = "This device does not support night mode"
        raise NotSupportedException(message)

    self.renderingControl.SetEQ(
        [("InstanceID", 0), ("EQType", "NightMode"), ("DesiredValue", int(night_mode))]
    )
# Buggy code
def dialog_mode(self, dialog_mode):
    """Switch on/off the speaker's dialog mode.

    :param dialog_mode: Enable or disable dialog mode
    :type dialog_mode: bool
    :raises NotSupportedException: If the device does not support
    dialog mode.
    """
    if not self.speaker_info:
        self.get_speaker_info()
    if "PLAYBAR" not in self.speaker_info["model_name"]:
        message = "This device does not support dialog mode"
        raise NotSupportedException(message)

    self.renderingControl.SetEQ(
        [
            ("InstanceID", 0),
            ("EQType", "DialogLevel"),
            ("DesiredValue", int(dialog_mode)),
        ]
    )


# Traceback (soco.exceptions.NotSupportedException)
my_zone
SoCo("192.168.2.253")
my_zone.get_speaker_info()
{u'display_version': '9.1', u'player_icon': '/img/icon-S11.png', u'uid': 'RINCON_XYZ', u'software_version': '45.1-56150', u'mac_address': u'MA-CA-DD-RE-S-S', u'hardware_version': '1.14.1.11-1', u'model_number': 'S11', u'serial_number': 'MA-CA-DD-RE-S-S:1', u'zone_name': 'Family Room', u'model_name': 'Sonos Playbase'}
my_zone.night_mode = True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/soco/core.py", line 813, in night_mode
raise NotSupportedException(message)
soco.exceptions.NotSupportedException: This device does not support night mode
my_zone.dialog_mode = True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/soco/core.py", line 851, in dialog_mode
raise NotSupportedException(message)
soco.exceptions.NotSupportedException: This device does not support dialog mode

# Fixed code
def dialog_mode(self, dialog_mode):
    """Switch on/off the speaker's dialog mode.

    :param dialog_mode: Enable or disable dialog mode
    :type dialog_mode: bool
    :raises NotSupportedException: If the device does not support
    dialog mode.
    """
    if not self.is_soundbar:
        message = "This device does not support dialog mode"
        raise NotSupportedException(message)

    self.renderingControl.SetEQ(
        [
            ("InstanceID", 0),
            ("EQType", "DialogLevel"),
            ("DesiredValue", int(dialog_mode)),
        ]
    )
# Buggy code
def scale_in(self, n):
    ids = self._executor.scale_in(n)
    if ids is not None:
        new_status = {}
        for id in ids:
            new_status[id] = JobStatus(JobState.CANCELLED)
            del self._status[id]
        self.send_monitoring_info(new_status, block_id_type="internal")
    return ids


# Traceback (RuntimeError)
2020-09-10 00:15:14 parsl.dataflow.dflow:509 [INFO]  Task 0 launched on executor medium
2020-09-10 00:15:14 workflow:68 [INFO]  Waiting for validation task to complete...
2020-09-10 00:15:17 parsl.providers.torque.torque:128 [DEBUG]  coerced job_id 1838438.wlm01 -> 1838438.wlm01
2020-09-10 00:15:17 parsl.dataflow.strategy:332 [DEBUG]  Executor medium has 0 active tasks, 0/1 running/pending blocks, and 0 connected workers
2020-09-10 00:15:17 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/akila/Documents/NUS_CSI/Parsl/parsl.git/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/akila/Documents/NUS_CSI/Parsl/parsl.git/parsl/dataflow/task_status_poller.py", line 66, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/akila/Documents/NUS_CSI/Parsl/parsl.git/parsl/dataflow/strategy.py", line 302, in _strategy_htex_auto_scale
for label, executor in self.dfk.executors.items():
RuntimeError: dictionary changed size during iteration
2020-09-10 00:15:22 parsl.providers.torque.torque:128 [DEBUG]  coerced job_id 1838438.wlm01 -> 1838438.wlm01

# Fixed code
def scale_in(self, n, force=True, max_idletime=None):
    if force and not max_idletime:
        ids = self._executor.scale_in(n)
    else:
        ids = self._executor.scale_in(n, force=force, max_idletime=max_idletime)
    if ids is not None:
        new_status = {}
        for id in ids:
            new_status[id] = JobStatus(JobState.CANCELLED)
            del self._status[id]
        self.send_monitoring_info(new_status, block_id_type="internal")
    return ids
# Buggy code
def monitor_wrapper(
    f, try_id, task_id, monitoring_hub_url, run_id, logging_level, sleep_dur
):
    """Internal
    Wrap the Parsl app with a function that will call the monitor function and point it at the correct pid when the task begins.
    """

    def wrapped(*args, **kwargs):
        command_q = Queue(maxsize=10)
        p = Process(
            target=monitor,
            args=(
                os.getpid(),
                try_id,
                task_id,
                monitoring_hub_url,
                run_id,
                command_q,
                logging_level,
                sleep_dur,
            ),
            name="Monitor-Wrapper-{}".format(task_id),
        )
        p.start()
        try:
            try:
                return f(*args, **kwargs)
            finally:
                command_q.put("Finished")
                p.join()
        finally:
            # There's a chance of zombification if the workers are killed by some signals
            p.terminate()
            p.join()

    return wrapped


# Traceback (AttributeError)
2020-08-08 17:10:06,436 - root - ERROR - Exception reading IO counters for child memory_percent. Recorded IO usage may be incomplete
Traceback (most recent call last):
File "/lus/theta-fs0/projects/CSC249ADCD08/colmena/env/lib/python3.7/site-packages/parsl/monitoring/monitoring.py", line 551, in monitor
d['psutil_process_disk_write'] += child.io_counters().write_bytes
AttributeError: 'Process' object has no attribute 'io_counters'

# Fixed code
def monitor_wrapper(
    f, try_id, task_id, monitoring_hub_url, run_id, logging_level, sleep_dur
):
    """Internal
    Wrap the Parsl app with a function that will call the monitor function and point it at the correct pid when the task begins.
    """

    def wrapped(*args, **kwargs):
        # Send first message to monitoring router
        try:
            monitor(
                os.getpid(),
                task_id,
                monitoring_hub_url,
                run_id,
                logging_level,
                sleep_dur,
                first_message=True,
            )
        except Exception:
            pass

        # create the monitor process and start
        p = Process(
            target=monitor,
            args=(
                os.getpid(),
                try_id,
                task_id,
                monitoring_hub_url,
                run_id,
                logging_level,
                sleep_dur,
            ),
            name="Monitor-Wrapper-{}".format(task_id),
        )
        p.start()

        try:
            return f(*args, **kwargs)
        finally:
            # There's a chance of zombification if the workers are killed by some signals
            p.terminate()
            p.join()

    return wrapped
# Buggy code
def wrapped(*args, **kwargs):
    command_q = Queue(maxsize=10)
    p = Process(
        target=monitor,
        args=(
            os.getpid(),
            try_id,
            task_id,
            monitoring_hub_url,
            run_id,
            command_q,
            logging_level,
            sleep_dur,
        ),
        name="Monitor-Wrapper-{}".format(task_id),
    )
    p.start()
    try:
        try:
            return f(*args, **kwargs)
        finally:
            command_q.put("Finished")
            p.join()
    finally:
        # There's a chance of zombification if the workers are killed by some signals
        p.terminate()
        p.join()


# Traceback (AttributeError)
2020-08-08 17:10:06,436 - root - ERROR - Exception reading IO counters for child memory_percent. Recorded IO usage may be incomplete
Traceback (most recent call last):
File "/lus/theta-fs0/projects/CSC249ADCD08/colmena/env/lib/python3.7/site-packages/parsl/monitoring/monitoring.py", line 551, in monitor
d['psutil_process_disk_write'] += child.io_counters().write_bytes
AttributeError: 'Process' object has no attribute 'io_counters'

# Fixed code
def wrapped(*args, **kwargs):
    # Send first message to monitoring router
    try:
        monitor(
            os.getpid(),
            task_id,
            monitoring_hub_url,
            run_id,
            logging_level,
            sleep_dur,
            first_message=True,
        )
    except Exception:
        pass

    # create the monitor process and start
    p = Process(
        target=monitor,
        args=(
            os.getpid(),
            try_id,
            task_id,
            monitoring_hub_url,
            run_id,
            logging_level,
            sleep_dur,
        ),
        name="Monitor-Wrapper-{}".format(task_id),
    )
    p.start()

    try:
        return f(*args, **kwargs)
    finally:
        # There's a chance of zombification if the workers are killed by some signals
        p.terminate()
        p.join()
# Buggy code
def status(self, job_ids):
    """Get the status of a list of jobs identified by their ids.

    Parameters
    ----------
    job_ids : list of str
        Identifiers for the jobs.

    Returns
    -------
    list of int
        The status codes of the requsted jobs.
    """

    all_states = []

    status = self.client.describe_instances(InstanceIds=list(job_ids))
    for r in status["Reservations"]:
        for i in r["Instances"]:
            instance_id = i["InstanceId"]
            instance_state = translate_table.get(i["State"]["Name"], JobState.UNKNOWN)
            self.resources[instance_id]["status"] = JobStatus(instance_state)
            all_states.extend([instance_state])

    return all_states


# Traceback (AttributeError)
2020-06-01 13:40:16.122 parsl.dataflow.task_status_poller:62 [DEBUG]  Polling
2020-06-01 13:40:16.126 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/benc/parsl/src/parsl/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/benc/parsl/src/parsl/parsl/dataflow/task_status_poller.py", line 64, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in _strategy_simple
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in <listcomp>
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
AttributeError: 'JobState' object has no attribute 'state'

# Fixed code
def status(self, job_ids):
    """Get the status of a list of jobs identified by their ids.

    Parameters
    ----------
    job_ids : list of str
        Identifiers for the jobs.

    Returns
    -------
    list of int
        The status codes of the requsted jobs.
    """

    all_states = []

    status = self.client.describe_instances(InstanceIds=list(job_ids))
    for r in status["Reservations"]:
        for i in r["Instances"]:
            instance_id = i["InstanceId"]
            instance_state = translate_table.get(i["State"]["Name"], JobState.UNKNOWN)
            instance_status = JobStatus(instance_state)
            self.resources[instance_id]["status"] = instance_status
            all_states.extend([instance_status])

    return all_states
# Buggy code
def status(self, job_ids):
    """Get the status of a list of jobs identified by the job identifiers
    returned from the submit request.

    Args:
         - job_ids (list) : A list of job identifiers

    Returns:
         - A list of JobStatus objects corresponding to each job_id in the job_ids list.

    Raises:
         - ExecutionProviderException or its subclasses

    """
    statuses = []
    for job_id in job_ids:
        instance = (
            self.client.instances()
            .get(instance=job_id, project=self.project_id, zone=self.zone)
            .execute()
        )
        self.resources[job_id]["status"] = JobStatus(
            translate_table[instance["status"]]
        )
        statuses.append(translate_table[instance["status"]])
    return statuses


# Traceback (AttributeError)
2020-06-01 13:40:16.122 parsl.dataflow.task_status_poller:62 [DEBUG]  Polling
2020-06-01 13:40:16.126 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/benc/parsl/src/parsl/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/benc/parsl/src/parsl/parsl/dataflow/task_status_poller.py", line 64, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in _strategy_simple
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in <listcomp>
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
AttributeError: 'JobState' object has no attribute 'state'

# Fixed code
def status(self, job_ids):
    """Get the status of a list of jobs identified by the job identifiers
    returned from the submit request.

    Args:
         - job_ids (list) : A list of job identifiers

    Returns:
         - A list of JobStatus objects corresponding to each job_id in the job_ids list.

    Raises:
         - ExecutionProviderException or its subclasses

    """
    statuses = []
    for job_id in job_ids:
        instance = (
            self.client.instances()
            .get(instance=job_id, project=self.project_id, zone=self.zone)
            .execute()
        )
        job_status = JobStatus(translate_table[instance["status"]])
        self.resources[job_id]["status"] = job_status
        statuses.append(job_status)
    return statuses
# Buggy code
def status(self, job_ids):
    """Get the status of a list of jobs identified by their ids.
    Parameters
    ----------
    job_ids : list of str
        Identifiers for the jobs.
    Returns
    -------
    list of int
        The status codes of the requsted jobs.
    """
    statuses = []
    logger.info("List VMs in resource group")
    for job_id in job_ids:
        try:
            vm = self.compute_client.virtual_machines.get(
                self.group_name, job_id, expand="instanceView"
            )
            status = vm.instance_view.statuses[1].display_status
            statuses.append(JobStatus(translate_table.get(status, JobState.UNKNOWN)))
        # This only happens when it is in ProvisionState/Pending
        except IndexError:
            statuses.append(JobStatus(JobState.PENDING))
    return statuses


# Traceback (AttributeError)
2020-06-01 13:40:16.122 parsl.dataflow.task_status_poller:62 [DEBUG]  Polling
2020-06-01 13:40:16.126 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/benc/parsl/src/parsl/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/benc/parsl/src/parsl/parsl/dataflow/task_status_poller.py", line 64, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in _strategy_simple
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in <listcomp>
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
AttributeError: 'JobState' object has no attribute 'state'

# Fixed code
def status(self, job_ids) -> List[JobStatus]:
    """Get the status of a list of jobs identified by their ids.
    Parameters
    ----------
    job_ids : list of str
        Identifiers for the jobs.
    Returns
    -------
    list of int
        The status codes of the requsted jobs.
    """
    statuses = []
    logger.info("List VMs in resource group")
    for job_id in job_ids:
        try:
            vm = self.compute_client.virtual_machines.get(
                self.group_name, job_id, expand="instanceView"
            )
            status = vm.instance_view.statuses[1].display_status
            statuses.append(JobStatus(translate_table.get(status, JobState.UNKNOWN)))
        # This only happens when it is in ProvisionState/Pending
        except IndexError:
            statuses.append(JobStatus(JobState.PENDING))
    return statuses
# Buggy code
def status(self, job_ids):
    """Get status of the list of jobs with job_ids

    Parameters
    ----------
    job_ids : list of strings
      List of job id strings

    Returns
    -------
    list of JobStatus objects
    """
    for job_id in job_ids:
        channel = self.resources[job_id]["channel"]
        status_command = "ps --pid {} | grep {}".format(
            self.resources[job_id]["job_id"], self.resources[job_id]["cmd"].split()[0]
        )
        retcode, stdout, stderr = channel.execute_wait(status_command)
        if retcode != 0 and self.resources[job_id]["status"].state == JobState.RUNNING:
            self.resources[job_id]["status"] = JobStatus(JobState.FAILED)

    return [self.resources[job_id]["status"] for job_id in job_ids]


# Traceback (AttributeError)
2020-06-01 13:40:16.122 parsl.dataflow.task_status_poller:62 [DEBUG]  Polling
2020-06-01 13:40:16.126 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/benc/parsl/src/parsl/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/benc/parsl/src/parsl/parsl/dataflow/task_status_poller.py", line 64, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in _strategy_simple
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in <listcomp>
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
AttributeError: 'JobState' object has no attribute 'state'

# Fixed code
def status(self, job_ids: List[Any]) -> List[JobStatus]:
    """Get status of the list of jobs with job_ids

    Parameters
    ----------
    job_ids : list of strings
      List of job id strings

    Returns
    -------
    list of JobStatus objects
    """
    for job_id in job_ids:
        channel = self.resources[job_id]["channel"]
        status_command = "ps --pid {} | grep {}".format(
            self.resources[job_id]["job_id"], self.resources[job_id]["cmd"].split()[0]
        )
        retcode, stdout, stderr = channel.execute_wait(status_command)
        if retcode != 0 and self.resources[job_id]["status"].state == JobState.RUNNING:
            self.resources[job_id]["status"] = JobStatus(JobState.FAILED)

    return [self.resources[job_id]["status"] for job_id in job_ids]
# Buggy code
def status(self, job_ids):
    """Get the status of a list of jobs identified by the job identifiers
    returned from the submit request.

    Args:
         - job_ids (list) : A list of job identifiers

    Returns:
         - A list of JobStatus objects corresponding to each job_id in the job_ids list.

    Raises:
         - ExecutionProviderException or its subclasses

    """
    if job_ids:
        self._status()
    return [self.resources[jid]["status"] for jid in job_ids]


# Traceback (AttributeError)
2020-06-01 13:40:16.122 parsl.dataflow.task_status_poller:62 [DEBUG]  Polling
2020-06-01 13:40:16.126 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/benc/parsl/src/parsl/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/benc/parsl/src/parsl/parsl/dataflow/task_status_poller.py", line 64, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in _strategy_simple
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in <listcomp>
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
AttributeError: 'JobState' object has no attribute 'state'

# Fixed code
def status(self, job_ids: List[Any]) -> List[JobStatus]:
    """Get the status of a list of jobs identified by the job identifiers
    returned from the submit request.

    Args:
         - job_ids (list) : A list of job identifiers

    Returns:
         - A list of JobStatus objects corresponding to each job_id in the job_ids list.

    Raises:
         - ExecutionProviderException or its subclasses

    """
    if job_ids:
        self._status()
    return [self.resources[jid]["status"] for jid in job_ids]
# Buggy code
def status(self, job_ids):
    """Get the status of a list of jobs identified by their ids.

    Parameters
    ----------
    job_ids : list of int
        Identifiers of jobs for which the status will be returned.

    Returns
    -------
    List of int
        Status codes for the requested jobs.

    """
    self._status()
    return [self.resources[jid]["status"] for jid in job_ids]


# Traceback (AttributeError)
2020-06-01 13:40:16.122 parsl.dataflow.task_status_poller:62 [DEBUG]  Polling
2020-06-01 13:40:16.126 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/benc/parsl/src/parsl/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/benc/parsl/src/parsl/parsl/dataflow/task_status_poller.py", line 64, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in _strategy_simple
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in <listcomp>
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
AttributeError: 'JobState' object has no attribute 'state'

# Fixed code
def status(self, job_ids: List[Any]) -> List[JobStatus]:
    """Get the status of a list of jobs identified by their ids.

    Parameters
    ----------
    job_ids : list of int
        Identifiers of jobs for which the status will be returned.

    Returns
    -------
    List of int
        Status codes for the requested jobs.

    """
    self._status()
    return [self.resources[jid]["status"] for jid in job_ids]
# Buggy code
def status(self, job_ids):
    """Get the status of a list of jobs identified by their ids.

    Args:
        - job_ids (List of ids) : List of identifiers for the jobs

    Returns:
        - List of status codes.

    """

    logger.debug("Checking status of: {0}".format(job_ids))
    for job_id in self.resources:
        retcode, stdout, stderr = self.channel.execute_wait(
            'ps -p {} > /dev/null 2> /dev/null; echo "STATUS:$?" '.format(
                self.resources[job_id]["remote_pid"]
            ),
            self.cmd_timeout,
        )
        if stdout:  # (is not None)
            for line in stdout.split("\n"):
                if line.startswith("STATUS:"):
                    status = line.split("STATUS:")[1].strip()
                    if status == "0":
                        self.resources[job_id]["status"] = JobStatus(JobState.RUNNING)
                    else:
                        self.resources[job_id]["status"] = JobStatus(JobState.FAILED)

    return [self.resources[jid]["status"] for jid in job_ids]


# Traceback (AttributeError)
2020-06-01 13:40:16.122 parsl.dataflow.task_status_poller:62 [DEBUG]  Polling
2020-06-01 13:40:16.126 parsl.dataflow.flow_control:114 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/home/benc/parsl/src/parsl/parsl/dataflow/flow_control.py", line 112, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/home/benc/parsl/src/parsl/parsl/dataflow/task_status_poller.py", line 64, in poll
self._strategy.strategize(self._poll_items, tasks)
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in _strategy_simple
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
File "/home/benc/parsl/src/parsl/parsl/dataflow/strategy.py", line 198, in <listcomp>
running = sum([1 for x in status.values() if x.state == JobState.RUNNING])
AttributeError: 'JobState' object has no attribute 'state'

# Fixed code
def status(self, job_ids: List[Any]) -> List[JobStatus]:
    """Get the status of a list of jobs identified by their ids.

    Args:
        - job_ids (List of ids) : List of identifiers for the jobs

    Returns:
        - List of status codes.

    """

    logger.debug("Checking status of: {0}".format(job_ids))
    for job_id in self.resources:
        retcode, stdout, stderr = self.channel.execute_wait(
            'ps -p {} > /dev/null 2> /dev/null; echo "STATUS:$?" '.format(
                self.resources[job_id]["remote_pid"]
            ),
            self.cmd_timeout,
        )
        if stdout:  # (is not None)
            for line in stdout.split("\n"):
                if line.startswith("STATUS:"):
                    status = line.split("STATUS:")[1].strip()
                    if status == "0":
                        self.resources[job_id]["status"] = JobStatus(JobState.RUNNING)
                    else:
                        self.resources[job_id]["status"] = JobStatus(JobState.FAILED)

    return [self.resources[jid]["status"] for jid in job_ids]
# Buggy code
def _status(self):
    """Update the resource dictionary with job statuses."""

    job_id_list = " ".join(self.resources.keys())
    cmd = "condor_q {0} -af:jr JobStatus".format(job_id_list)
    retcode, stdout, stderr = self.execute_wait(cmd)
    """
        Example output:

        $ condor_q 34524642.0 34524643.0 -af:jr JobStatus
        34524642.0 2
        34524643.0 1
        """

    for line in stdout.strip().split("\n"):
        parts = line.split()
        job_id = parts[0]
        status = translate_table.get(parts[1], "UNKNOWN")
        self.resources[job_id]["status"] = status


# Traceback (IndexError)
2019-09-20 15:32:16.535 parsl.dataflow.flow_control:142 [ERROR]  Flow control callback threw an exception - logging and proceeding anyway
Traceback (most recent call last):
File "/afs/crc.nd.edu/user/a/awoodard/.local/lib/python3.6/site-packages/parsl/dataflow/flow_control.py", line 140, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/afs/crc.nd.edu/user/a/awoodard/.local/lib/python3.6/site-packages/parsl/dataflow/strategy.py", line 177, in _strategy_simple
status = executor.status()
File "/afs/crc.nd.edu/user/a/awoodard/.local/lib/python3.6/site-packages/parsl/executors/high_throughput/executor.py", line 620, in status
status = self.provider.status(list(self.blocks.values()))
File "/afs/crc.nd.edu/user/a/awoodard/.local/lib/python3.6/site-packages/parsl/providers/condor/condor.py", line 160, in status
self._status()
File "/afs/crc.nd.edu/user/a/awoodard/.local/lib/python3.6/site-packages/parsl/providers/condor/condor.py", line 142, in _status
job_id = parts[0]
IndexError: list index out of range

# Fixed code
def _status(self):
    """Update the resource dictionary with job statuses."""

    job_id_list = " ".join(self.resources.keys())
    cmd = "condor_q {0} -af:jr JobStatus".format(job_id_list)
    retcode, stdout, stderr = self.execute_wait(cmd)
    """
        Example output:

        $ condor_q 34524642.0 34524643.0 -af:jr JobStatus
        34524642.0 2
        34524643.0 1
        """

    for line in stdout.splitlines():
        parts = line.strip().split()
        job_id = parts[0]
        status = translate_table.get(parts[1], "UNKNOWN")
        self.resources[job_id]["status"] = status
# Buggy code
def y_axis_setup():
    items = []

    for app, tasks in apps_dict.items():
        tmp = []
        if option == "avg":
            task = (
                df_resources[df_resources["task_id"] == app][type]
                .astype("float")
                .mean()
            )
        elif option == "max":
            task = max(
                df_resources[df_resources["task_id"] == app][type].astype("float")
            )

        for i in range(len(x_axis) - 1):
            a = task >= x_axis[i]
            b = task < x_axis[i + 1]
            tmp.append(a & b)
        items = np.sum([items, tmp], axis=0)
    return items


# Traceback (ZeroDivisionError)
[2019-05-03 18:18:01,362] ERROR in app: Exception on /workflow/9294c39d-a64d-4ad5-9ff8-4b8d757c1af1/resource_usage [GET]
Traceback (most recent call last):
File "/Users/awoodard/software/miniconda3/envs/parsl/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Users/awoodard/software/miniconda3/envs/parsl/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/awoodard/software/miniconda3/envs/parsl/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/awoodard/software/miniconda3/envs/parsl/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/awoodard/software/miniconda3/envs/parsl/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/awoodard/software/miniconda3/envs/parsl/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/awoodard/ci/viz_server/viz_server/views.py", line 145, in workflow_resources
df_resources, df_task, type='psutil_process_time_user', label='CPU Time Distribution', option='avg'),
File "/Users/awoodard/ci/viz_server/viz_server/plots/default/workflow_resource_plots.py", line 15, in resource_distribution_plot
for i in np.arange(min_range, max_range + time_step, time_step):
ZeroDivisionError: float division by zero

# Fixed code
def y_axis_setup():
    items = [0] * len(x_axis)

    for app, tasks in apps_dict.items():
        if option == "avg":
            task = (
                df_resources[df_resources["task_id"] == app][type]
                .astype("float")
                .mean()
            )
        elif option == "max":
            task = max(
                df_resources[df_resources["task_id"] == app][type].astype("float")
            )

        for i in range(len(x_axis) - 1):
            a = task >= x_axis[i]
            b = task < x_axis[i + 1]
            if a and b:
                items[i] += 1
        if task >= x_axis[-1]:
            items[-1] += 1
    return items
# Buggy code
def status(self, job_ids):
    """Get the status of a list of jobs identified by the job identifiers
    returned from the submit request.

    Args:
         - job_ids (list) : A list of job identifiers

    Returns:
         - A list of status from ['PENDING', 'RUNNING', 'CANCELLED', 'COMPLETED',
           'FAILED', 'TIMEOUT'] corresponding to each job_id in the job_ids list.

    Raises:
         - ExecutionProviderExceptions or its subclasses

    """
    self._status()
    return [self.resources[jid]["status"] for jid in job_ids]


# Traceback (KeyError)
Traceback (most recent call last):
File "/Users/awoodard/software/anaconda3/envs/parsl_py36/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/Users/awoodard/software/anaconda3/envs/parsl_py36/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/Users/awoodard/ci/parsl/parsl/dataflow/flow_control.py", line 121, in _wake_up_timer
self.make_callback(kind='timer')
File "/Users/awoodard/ci/parsl/parsl/dataflow/flow_control.py", line 141, in make_callback
self.callback(tasks=self._event_buffer, kind=kind)
File "/Users/awoodard/ci/parsl/parsl/dataflow/strategy.py", line 162, in _strategy_simple
status = exc.status()
File "/Users/awoodard/ci/parsl/parsl/executors/ipp.py", line 253, in status
status = self.execution_provider.status(self.engines)
File "/Users/awoodard/ci/libsubmit/libsubmit/providers/cluster_provider.py", line 174, in status
self._status()
File "/Users/awoodard/ci/libsubmit/libsubmit/providers/slurm/slurm.py", line 141, in _status
self.resources[job_id]['status'] = status
KeyError: '41784475_20'

# Fixed code
def status(self, job_ids):
    """Get the status of a list of jobs identified by the job identifiers
    returned from the submit request.

    Args:
         - job_ids (list) : A list of job identifiers

    Returns:
         - A list of status from ['PENDING', 'RUNNING', 'CANCELLED', 'COMPLETED',
           'FAILED', 'TIMEOUT'] corresponding to each job_id in the job_ids list.

    Raises:
         - ExecutionProviderExceptions or its subclasses

    """
    if job_ids:
        self._status()
    return [self.resources[jid]["status"] for jid in job_ids]
# Buggy code
def process(self, operation: Operation):
    filepath = get_absolute_path(self._root_dir, operation.filename)
    if not os.path.exists(filepath):
        raise FileNotFoundError(f"Could not find {filepath}")
    if not os.path.isfile(filepath):
        raise ValueError(f"Not a file: {filepath}")

    self.log.debug(f"Processing: {filepath}")
    file_dir = os.path.dirname(filepath)
    argv = self._create_execute_command(filepath, file_dir)
    envs = operation.env_vars_as_dict(self.log)
    try:
        run(argv, cwd=file_dir, env=envs, check=True)
    except Exception as ex:
        raise RuntimeError(f"Internal error executing {filepath}: {ex}") from ex


# Traceback (subprocess.CalledProcessError)
Traceback (most recent call last):
File "/opt/conda/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 151, in process
subprocess.run(argv, cwd=file_dir, env=envs, check=True)
File "/opt/conda/lib/python3.7/subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['papermill', '/home/jovyan/work/Untitled.ipynb', '/home/jovyan/work/Untitled.ipynb', '--cwd', '/home/jovyan/work']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/conda/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 70, in process
operation_processor.process(operation)
File "/opt/conda/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 154, in process
raise RuntimeError(f'Internal error executing {filepath}') from ex
RuntimeError: Internal error executing /home/jovyan/work/Untitled.ipynb

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/conda/lib/python3.7/site-packages/tornado/web.py", line 1703, in _execute
result = await result
File "/opt/conda/lib/python3.7/site-packages/elyra/pipeline/handlers.py", line 89, in post
response = await PipelineProcessorManager.instance().process(pipeline)
File "/opt/conda/lib/python3.7/site-packages/elyra/pipeline/processor.py", line 69, in process
res = await asyncio.get_event_loop().run_in_executor(None, processor.process, pipeline)
File "/opt/conda/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/opt/conda/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 72, in process
raise RuntimeError(f'Error processing operation {operation.name}.') from ex
RuntimeError: Error processing operation Untitled.

# Fixed code
def process(self, operation: Operation):
    raise NotImplementedError
# Buggy code
def _validate_parameters(self):
    self._confirm_required("name", self.name)
    self._confirm_required("display_name", self.display_name)
    self._confirm_required("api_endpoint", self.api_endpoint)
    self._confirm_required("cos_endpoint", self.cos_endpoint)
    self._confirm_required("cos_bucket", self.cos_bucket)


# Traceback (KeyError)
[E 14:28:56.246 LabApp] Uncaught exception POST /scheduler?1574720936239 (::1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/scheduler?1574720936239', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/web.py", line 1697, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/opt/anaconda3/lib/python3.6/site-packages/ai_workspace/scheduler/handler.py", line 67, in post
cos_username = runtime_configuration.metadata['cos_username']
KeyError: 'cos_username'

# Fixed code
def _validate_parameters(self):
    self._confirm_required("name", self.name)
    self._confirm_required("display_name", self.display_name)
    self._confirm_required("api_endpoint", self.api_endpoint)
    self._confirm_required("cos_endpoint", self.cos_endpoint)
    self._confirm_required("cos_username", self.cos_username)
    self._confirm_required("cos_password", self.cos_password)
    self._confirm_required("cos_bucket", self.cos_bucket)
# Buggy code
def manage_DAVget(self):
    """Gets the document source"""
    # The default implementation calls PrincipiaSearchSource
    return self.PrincipiaSearchSource()


# Traceback (AttributeError)
2020-03-05 12:08:22 ERROR [waitress:357][waitress] Exception while serving /foo/m
Traceback (most recent call last):
File "/home/ajung/src/zope/lib/python3.7/site-packages/waitress/channel.py", line 349, in service
task.service()
File "/home/ajung/src/zope/lib/python3.7/site-packages/waitress/task.py", line 169, in service
self.execute()
File "/home/ajung/src/zope/lib/python3.7/site-packages/waitress/task.py", line 439, in execute
app_iter = self.channel.server.application(environ, start_response)
File "/home/ajung/src/zope/lib/python3.7/site-packages/ZPublisher/httpexceptions.py", line 30, in __call__
return self.application(environ, start_response)
File "/home/ajung/src/zope/lib/python3.7/site-packages/paste/translogger.py", line 69, in __call__
return self.application(environ, replacement_start_response)
File "/home/ajung/src/zope/lib/python3.7/site-packages/ZPublisher/WSGIPublisher.py", line 364, in publish_module
response = _publish(request, new_mod_info)
File "/home/ajung/src/zope/lib/python3.7/site-packages/ZPublisher/WSGIPublisher.py", line 267, in publish
bind=1)
File "/home/ajung/src/zope/lib/python3.7/site-packages/ZPublisher/mapply.py", line 85, in mapply
return debug(object, args, context)
File "/home/ajung/src/zope/lib/python3.7/site-packages/ZPublisher/WSGIPublisher.py", line 68, in call_object
return obj(*args)
File "/home/ajung/src/zope/lib/python3.7/site-packages/webdav/Resource.py", line 680, in manage_DAVget
return self.PrincipiaSearchSource()
AttributeError: 'RequestContainer' object has no attribute 'PrincipiaSearchSource'

# Fixed code
def manage_DAVget(self):
    """Gets the document source or file data.

    This implementation is a last resort fallback. The subclass should
    override this method to provide a more appropriate implementation.

    Using PrincipiaSearchSource, if it exists. It is one of the few shared
    interfaces still around in common Zope content objects.
    """
    if getattr(aq_base(self), "PrincipiaSearchSource", None) is not None:
        return self.PrincipiaSearchSource()

    # If it doesn't exist, give up.
    return ""