gurudesh/pytracebugs huggingface dataset:
# Buggy code
def run_rsync_down(self, source, target, redirect=None):
    if target.startswith("~"):
        target = "/root" + target[1:]

    try:
        self.process_runner.check_call(
            [
                KUBECTL_RSYNC,
                "-avz",
                "{}@{}:{}".format(self.node_id, self.namespace, source),
                target,
            ],
            stdout=redirect,
            stderr=redirect,
        )
    except Exception as e:
        logger.warning(
            self.log_prefix
            + "rsync failed: '{}'. Falling back to 'kubectl cp'".format(e)
        )
        self.process_runner.check_call(
            self.kubectl
            + ["cp", "{}/{}:{}".format(self.namespace, self.node_id, source), target],
            stdout=redirect,
            stderr=redirect,
        )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/swang/ray/python/ray/worker.py", line 2121, in get
raise value.as_instanceof_cause()
ray.exceptions.RayTaskError(UnreconstructableError): <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "error.py", line 11, in <module>
ray.get(x[0])
File "/Users/swang/ray/python/ray/worker.py", line 2131, in get
return values
File "python/ray/includes/libcoreworker.pxi", line 32, in ray._raylet.ProfileEvent.__exit__
"value": str(value),
File "/Users/swang/ray/python/ray/exceptions.py", line 155, in __str__
self.object_id.hex(),
AttributeError: 'RayTaskError(UnreconstructableError)' object has no attribute 'object_id'
2019-10-08 10:35:18,456 WARNING worker.py:1619 -- The task with ID ffffffffffffffffffff01000000 is a driver task and so the object created by ray.put could not be reconstructed.

# Fixed code
def run_rsync_down(self, source, target, redirect=None):
    self.set_ssh_ip_if_required()
    self.process_runner.check_call(
        [
            "rsync",
            "--rsh",
            " ".join(["ssh"] + self.get_default_ssh_options(120)),
            "-avz",
            "{}@{}:{}".format(self.ssh_user, self.ssh_ip, source),
            target,
        ],
        stdout=redirect,
        stderr=redirect,
    )
# Buggy code
def as_instanceof_cause(self):
    """Returns copy that is an instance of the cause's Python class.

    The returned exception will inherit from both RayTaskError and the
    cause class.
    """

    if issubclass(RayTaskError, self.cause_cls):
        return self  # already satisfied

    class cls(RayTaskError, self.cause_cls):
        def __init__(self, function_name, traceback_str, cause_cls, proctitle, pid, ip):
            RayTaskError.__init__(
                self, function_name, traceback_str, cause_cls, proctitle, pid, ip
            )

    name = "RayTaskError({})".format(self.cause_cls.__name__)
    cls.__name__ = name
    cls.__qualname__ = name

    return cls(
        self.function_name,
        self.traceback_str,
        self.cause_cls,
        self.proctitle,
        self.pid,
        self.ip,
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/swang/ray/python/ray/worker.py", line 2121, in get
raise value.as_instanceof_cause()
ray.exceptions.RayTaskError(UnreconstructableError): <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "error.py", line 11, in <module>
ray.get(x[0])
File "/Users/swang/ray/python/ray/worker.py", line 2131, in get
return values
File "python/ray/includes/libcoreworker.pxi", line 32, in ray._raylet.ProfileEvent.__exit__
"value": str(value),
File "/Users/swang/ray/python/ray/exceptions.py", line 155, in __str__
self.object_id.hex(),
AttributeError: 'RayTaskError(UnreconstructableError)' object has no attribute 'object_id'
2019-10-08 10:35:18,456 WARNING worker.py:1619 -- The task with ID ffffffffffffffffffff01000000 is a driver task and so the object created by ray.put could not be reconstructed.

# Fixed code
def as_instanceof_cause(self):
    """Returns copy that is an instance of the cause's Python class.

    The returned exception will inherit from both RayTaskError and the
    cause class.
    """

    if issubclass(RayTaskError, self.cause_cls):
        return self  # already satisfied

    if issubclass(self.cause_cls, RayError):
        return self  # don't try to wrap ray internal errors

    class cls(RayTaskError, self.cause_cls):
        def __init__(self, function_name, traceback_str, cause_cls, proctitle, pid, ip):
            RayTaskError.__init__(
                self, function_name, traceback_str, cause_cls, proctitle, pid, ip
            )

    name = "RayTaskError({})".format(self.cause_cls.__name__)
    cls.__name__ = name
    cls.__qualname__ = name

    return cls(
        self.function_name,
        self.traceback_str,
        self.cause_cls,
        self.proctitle,
        self.pid,
        self.ip,
    )
# Buggy code
def reset_partition_coords(self, partitions=None):
    partitions = np.array(partitions)

    for partition in partitions:
        partition_mask = self._coord_df["partition"] == partition
        # Since we are replacing columns with RangeIndex inside the
        # partition, we have to make sure that our reference to it is
        # updated as well.
        try:
            self._coord_df.loc[partition_mask, "index_within_partition"] = [
                p for p in range(sum(partition_mask))
            ]
        except ValueError:
            # Copy the arrow sealed dataframe so we can mutate it.
            # We only do this the first time we try to mutate the sealed.
            self._coord_df = self._coord_df.copy()
            self._coord_df.loc[partition_mask, "index_within_partition"] = [
                p for p in range(sum(partition_mask))
            ]


# Traceback (IndexError)
Remote function ray.dataframe.utils._deploy_func failed with:

Traceback (most recent call last):
File "/home/peter/workspace/ray/python/ray/dataframe/utils.py", line 132, in _deploy_func
return func(dataframe, *args)
File "/home/peter/workspace/ray/python/ray/dataframe/dataframe.py", line 4728, in del_helper
cols = df.columns[to_delete]  # either int or an array of ints
File "/home/peter/workspace/ray_env/lib/python3.6/site-packages/pandas/core/indexes/range.py", line 544, in __getitem__
return super_getitem(key)
File "/home/peter/workspace/ray_env/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 1754, in __getitem__
result = getitem(key)
IndexError: index 0 is out of bounds for axis 1 with size 0


You can inspect errors by running

ray.error_info()

If this driver is hanging, start a new one with

ray.init(redis_address="192.168.0.114:49682")

# Fixed code
def reset_partition_coords(self, partitions=None):
    partitions = np.array(partitions)

    for partition in partitions:
        partition_mask = self._coord_df["partition"] == partition
        # Since we are replacing columns with RangeIndex inside the
        # partition, we have to make sure that our reference to it is
        # updated as well.
        try:
            self._coord_df.loc[partition_mask, "index_within_partition"] = np.arange(
                sum(partition_mask)
            ).astype(int)
        except ValueError:
            # Copy the arrow sealed dataframe so we can mutate it.
            # We only do this the first time we try to mutate the sealed.
            self._coord_df = self._coord_df.copy()
            self._coord_df.loc[partition_mask, "index_within_partition"] = np.arange(
                sum(partition_mask)
            ).astype(int)
# Buggy code
def __init__(
    self, registry, config, policy_params, env_creator, noise, min_task_runtime=0.2
):
    self.min_task_runtime = min_task_runtime
    self.config = config
    self.policy_params = policy_params
    self.noise = SharedNoiseTable(noise)

    self.env = env_creator(config["env_config"])
    self.preprocessor = ModelCatalog.get_preprocessor(registry, self.env)

    self.sess = utils.make_session(single_threaded=True)
    self.policy = policies.GenericPolicy(
        registry,
        self.sess,
        self.env.action_space,
        self.preprocessor,
        config["observation_filter"],
        **policy_params,
    )


# Traceback (_frozen_importlib._DeadlockError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1720, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/rllib/__init__.py", line 17, in <module>
_register_all()
File "/home/ubuntu/ray/python/ray/rllib/__init__.py", line 14, in _register_all
register_trainable(key, get_agent_class(key))
File "/home/ubuntu/ray/python/ray/rllib/agent.py", line 229, in get_agent_class
from ray.rllib import es
File "/home/ubuntu/ray/python/ray/rllib/es/__init__.py", line 1, in <module>
from ray.rllib.es.es import (ESAgent, DEFAULT_CONFIG)
File "/home/ubuntu/ray/python/ray/rllib/es/es.py", line 19, in <module>
from ray.rllib.es import policies
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 168, in __enter__
File "<frozen importlib._bootstrap>", line 110, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('ray.rllib.es.policies') at 139937598221224

# Fixed code
def __init__(
    self, registry, config, policy_params, env_creator, noise, min_task_runtime=0.2
):
    self.min_task_runtime = min_task_runtime
    self.config = config
    self.policy_params = policy_params
    self.noise = SharedNoiseTable(noise)

    self.env = env_creator(config["env_config"])
    from ray.rllib import models

    self.preprocessor = models.ModelCatalog.get_preprocessor(registry, self.env)

    self.sess = utils.make_session(single_threaded=True)
    self.policy = policies.GenericPolicy(
        registry,
        self.sess,
        self.env.action_space,
        self.preprocessor,
        config["observation_filter"],
        **policy_params,
    )
# Buggy code
def _become_actor(self, task):
    """Turn this worker into an actor.

    Args:
        task: The actor creation task.
    """
    assert self.actor_id == NIL_ACTOR_ID
    arguments = task.arguments()
    assert len(arguments) == 1
    self.actor_id = task.actor_creation_id().id()
    class_id = arguments[0]

    key = b"ActorClass:" + class_id

    # Wait for the actor class key to have been imported by the import
    # thread. TODO(rkn): It shouldn't be possible to end up in an infinite
    # loop here, but we should push an error to the driver if too much time
    # is spent here.
    while key not in self.imported_actor_classes:
        time.sleep(0.001)

    self.fetch_and_register_actor(key, task.required_resources(), self)


# Traceback (_frozen_importlib._DeadlockError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1720, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/rllib/__init__.py", line 17, in <module>
_register_all()
File "/home/ubuntu/ray/python/ray/rllib/__init__.py", line 14, in _register_all
register_trainable(key, get_agent_class(key))
File "/home/ubuntu/ray/python/ray/rllib/agent.py", line 229, in get_agent_class
from ray.rllib import es
File "/home/ubuntu/ray/python/ray/rllib/es/__init__.py", line 1, in <module>
from ray.rllib.es.es import (ESAgent, DEFAULT_CONFIG)
File "/home/ubuntu/ray/python/ray/rllib/es/es.py", line 19, in <module>
from ray.rllib.es import policies
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 168, in __enter__
File "<frozen importlib._bootstrap>", line 110, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('ray.rllib.es.policies') at 139937598221224

# Fixed code
def _become_actor(self, task):
    """Turn this worker into an actor.

    Args:
        task: The actor creation task.
    """
    assert self.actor_id == NIL_ACTOR_ID
    arguments = task.arguments()
    assert len(arguments) == 1
    self.actor_id = task.actor_creation_id().id()
    class_id = arguments[0]

    key = b"ActorClass:" + class_id

    # Wait for the actor class key to have been imported by the import
    # thread. TODO(rkn): It shouldn't be possible to end up in an infinite
    # loop here, but we should push an error to the driver if too much time
    # is spent here.
    while key not in self.imported_actor_classes:
        time.sleep(0.001)

    with self.lock:
        self.fetch_and_register_actor(key, task.required_resources(), self)
# Buggy code
def __init__(
    self,
    actor_id,
    actor_handle_id,
    actor_cursor,
    actor_counter,
    actor_method_names,
    actor_method_num_return_vals,
    method_signatures,
    checkpoint_interval,
    class_name,
):
    self.actor_id = actor_id
    self.actor_handle_id = actor_handle_id
    self.actor_cursor = actor_cursor
    self.actor_counter = actor_counter
    self.actor_method_names = actor_method_names
    self.actor_method_num_return_vals = actor_method_num_return_vals
    # TODO(swang): Fetch this information from Redis so that we don't have
    # to fall back to pickle.
    self.method_signatures = method_signatures
    self.checkpoint_interval = checkpoint_interval
    self.class_name = class_name


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def __init__(
    self,
    actor_id,
    class_id,
    actor_handle_id,
    actor_cursor,
    actor_counter,
    actor_method_names,
    actor_method_num_return_vals,
    method_signatures,
    checkpoint_interval,
    class_name,
    actor_creation_dummy_object_id,
    actor_creation_resources,
    actor_method_cpus,
):
    # TODO(rkn): Some of these fields are probably not necessary. We should
    # strip out the unnecessary fields to keep actor handles lightweight.
    self.actor_id = actor_id
    self.class_id = class_id
    self.actor_handle_id = actor_handle_id
    self.actor_cursor = actor_cursor
    self.actor_counter = actor_counter
    self.actor_method_names = actor_method_names
    self.actor_method_num_return_vals = actor_method_num_return_vals
    # TODO(swang): Fetch this information from Redis so that we don't have
    # to fall back to pickle.
    self.method_signatures = method_signatures
    self.checkpoint_interval = checkpoint_interval
    self.class_name = class_name
    self.actor_creation_dummy_object_id = actor_creation_dummy_object_id
    self.actor_creation_resources = actor_creation_resources
    self.actor_method_cpus = actor_method_cpus
# Buggy code
def wrap_actor_handle(actor_handle):
    """Wrap the ActorHandle to store the fields.

    Args:
        actor_handle: The ActorHandle instance to wrap.

    Returns:
        An ActorHandleWrapper instance that stores the ActorHandle's fields.
    """
    wrapper = ActorHandleWrapper(
        actor_handle._ray_actor_id,
        compute_actor_handle_id(
            actor_handle._ray_actor_handle_id, actor_handle._ray_actor_forks
        ),
        actor_handle._ray_actor_cursor,
        0,  # Reset the actor counter.
        actor_handle._ray_actor_method_names,
        actor_handle._ray_actor_method_num_return_vals,
        actor_handle._ray_method_signatures,
        actor_handle._ray_checkpoint_interval,
        actor_handle._ray_class_name,
    )
    actor_handle._ray_actor_forks += 1
    return wrapper


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def wrap_actor_handle(actor_handle):
    """Wrap the ActorHandle to store the fields.

    Args:
        actor_handle: The ActorHandle instance to wrap.

    Returns:
        An ActorHandleWrapper instance that stores the ActorHandle's fields.
    """
    wrapper = ActorHandleWrapper(
        actor_handle._ray_actor_id,
        actor_handle._ray_class_id,
        compute_actor_handle_id(
            actor_handle._ray_actor_handle_id, actor_handle._ray_actor_forks
        ),
        actor_handle._ray_actor_cursor,
        0,  # Reset the actor counter.
        actor_handle._ray_actor_method_names,
        actor_handle._ray_actor_method_num_return_vals,
        actor_handle._ray_method_signatures,
        actor_handle._ray_checkpoint_interval,
        actor_handle._ray_class_name,
        actor_handle._ray_actor_creation_dummy_object_id,
        actor_handle._ray_actor_creation_resources,
        actor_handle._ray_actor_method_cpus,
    )
    actor_handle._ray_actor_forks += 1
    return wrapper
# Buggy code
def _manual_init(
    self,
    actor_id,
    actor_handle_id,
    actor_cursor,
    actor_counter,
    actor_method_names,
    actor_method_num_return_vals,
    method_signatures,
    checkpoint_interval,
):
    self._ray_actor_id = actor_id
    self._ray_actor_handle_id = actor_handle_id
    self._ray_actor_cursor = actor_cursor
    self._ray_actor_counter = actor_counter
    self._ray_actor_method_names = actor_method_names
    self._ray_actor_method_num_return_vals = actor_method_num_return_vals
    self._ray_method_signatures = method_signatures
    self._ray_checkpoint_interval = checkpoint_interval
    self._ray_class_name = class_name
    self._ray_actor_forks = 0


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def _manual_init(
    self,
    actor_id,
    class_id,
    actor_handle_id,
    actor_cursor,
    actor_counter,
    actor_method_names,
    actor_method_num_return_vals,
    method_signatures,
    checkpoint_interval,
    actor_creation_dummy_object_id,
    actor_creation_resources,
    actor_method_cpus,
):
    self._ray_actor_id = actor_id
    self._ray_class_id = class_id
    self._ray_actor_handle_id = actor_handle_id
    self._ray_actor_cursor = actor_cursor
    self._ray_actor_counter = actor_counter
    self._ray_actor_method_names = actor_method_names
    self._ray_actor_method_num_return_vals = actor_method_num_return_vals
    self._ray_method_signatures = method_signatures
    self._ray_checkpoint_interval = checkpoint_interval
    self._ray_class_name = class_name
    self._ray_actor_forks = 0
    self._ray_actor_creation_dummy_object_id = actor_creation_dummy_object_id
    self._ray_actor_creation_resources = actor_creation_resources
    self._ray_actor_method_cpus = actor_method_cpus
# Buggy code
def __del__(self):
    """Kill the worker that is running this actor."""
    # TODO(swang): Also clean up forked actor handles.
    # Kill the worker if this is the original actor handle, created
    # with Class.remote().
    if (
        ray.worker.global_worker.connected
        and self._ray_actor_handle_id.id() == ray.worker.NIL_ACTOR_ID
    ):
        self._actor_method_call("__ray_terminate__", args=[self._ray_actor_id.id()])


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def __del__(self):
    """Kill the worker that is running this actor."""
    # TODO(swang): Also clean up forked actor handles.
    # Kill the worker if this is the original actor handle, created
    # with Class.remote().
    if (
        ray.worker.global_worker.connected
        and self._ray_actor_handle_id.id() == ray.worker.NIL_ACTOR_ID
    ):
        # TODO(rkn): Should we be passing in the actor cursor as a
        # dependency here?
        self._actor_method_call("__ray_terminate__", args=[self._ray_actor_id.id()])
# Buggy code
def __ray_terminate__(self, actor_id):
    # Record that this actor has been removed so that if this node
    # dies later, the actor won't be recreated. Alternatively, we could
    # remove the actor key from Redis here.
    ray.worker.global_worker.redis_client.hset(b"Actor:" + actor_id, "removed", True)
    # Release the GPUs that this worker was using.
    if len(ray.get_gpu_ids()) > 0:
        release_gpus_in_use(
            ray.worker.global_worker.driver_id,
            ray.worker.global_worker.local_scheduler_id,
            ray.get_gpu_ids(),
            ray.worker.global_worker.redis_client,
        )
    # Disconnect the worker from the local scheduler. The point of this
    # is so that when the worker kills itself below, the local
    # scheduler won't push an error message to the driver.
    ray.worker.global_worker.local_scheduler_client.disconnect()
    import os

    os._exit(0)


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def __ray_terminate__(self, actor_id):
    # Record that this actor has been removed so that if this node
    # dies later, the actor won't be recreated. Alternatively, we could
    # remove the actor key from Redis here.
    ray.worker.global_worker.redis_client.hset(b"Actor:" + actor_id, "removed", True)
    # Disconnect the worker from the local scheduler. The point of this
    # is so that when the worker kills itself below, the local
    # scheduler won't push an error message to the driver.
    ray.worker.global_worker.local_scheduler_client.disconnect()
    import os

    os._exit(0)
# Buggy code
def register_trainable(name, trainable):
    """Register a trainable function or class.

    Args:
        name (str): Name to register.
        trainable (obj): Function or tune.Trainable clsas. Functions must
            take (config, status_reporter) as arguments and will be
            automatically converted into a class during registration.
    """

    if isinstance(trainable, FunctionType):
        trainable = wrap_function(trainable)
    if not issubclass(trainable, Trainable):
        raise TypeError("Second argument must be convertable to Trainable", trainable)
    _default_registry.register(TRAINABLE_CLASS, name, trainable)


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def register_trainable(name, trainable):
    """Register a trainable function or class.

    Args:
        name (str): Name to register.
        trainable (obj): Function or tune.Trainable clsas. Functions must
            take (config, status_reporter) as arguments and will be
            automatically converted into a class during registration.
    """

    from ray.tune.trainable import Trainable, wrap_function

    if isinstance(trainable, FunctionType):
        trainable = wrap_function(trainable)
    if not issubclass(trainable, Trainable):
        raise TypeError("Second argument must be convertable to Trainable", trainable)
    _default_registry.register(TRAINABLE_CLASS, name, trainable)
# Buggy code
def register(self, category, key, value):
    if category not in KNOWN_CATEGORIES:
        raise TuneError(
            "Unknown category {} not among {}".format(category, KNOWN_CATEGORIES)
        )
    self._all_objects[(category, key)] = value


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def register(self, category, key, value):
    if category not in KNOWN_CATEGORIES:
        from ray.tune import TuneError

        raise TuneError(
            "Unknown category {} not among {}".format(category, KNOWN_CATEGORIES)
        )
    self._all_objects[(category, key)] = value
# Buggy code
def worker_task(ps, batch_size=50):
    # Download MNIST.
    mnist = input_data.read_data_sets("MNIST_data", one_hot=True)

    # Initialize the model.
    net = model.SimpleCNN()
    keys = net.get_weights()[0]

    while True:
        # Get the current weights from the parameter server.
        weights = ray.get(ps.pull.remote(keys))
        net.set_weights(keys, weights)

        # Compute an update and push it to the parameter server.
        xs, ys = mnist.train.next_batch(batch_size)
        gradients = net.compute_update(xs, ys)
        ps.push.remote(keys, gradients)


# Traceback (tensorflow.python.framework.errors_impl.AlreadyExistsError)
Remote function __main__.worker_task failed with:

Traceback (most recent call last):
File "async_parameter_server.py", line 40, in worker_task
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py", line 245, in read_data_sets
source_url + TRAIN_LABELS)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/base.py", line 209, in maybe_download
gfile.Copy(temp_file_name, filepath)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 385, in copy
compat.as_bytes(oldpath), compat.as_bytes(newpath), overwrite, status)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.AlreadyExistsError: file already exists

# Fixed code
def worker_task(ps, worker_index, batch_size=50):
    # Download MNIST.
    mnist = model.download_mnist_retry(seed=worker_index)

    # Initialize the model.
    net = model.SimpleCNN()
    keys = net.get_weights()[0]

    while True:
        # Get the current weights from the parameter server.
        weights = ray.get(ps.pull.remote(keys))
        net.set_weights(keys, weights)

        # Compute an update and push it to the parameter server.
        xs, ys = mnist.train.next_batch(batch_size)
        gradients = net.compute_update(xs, ys)
        ps.push.remote(keys, gradients)
# Buggy code
def __init__(self, worker_index, batch_size=50):
    self.worker_index = worker_index
    self.batch_size = batch_size
    self.mnist = input_data.read_data_sets(
        "MNIST_data", one_hot=True, seed=worker_index
    )
    self.net = model.SimpleCNN()


# Traceback (tensorflow.python.framework.errors_impl.AlreadyExistsError)
Remote function __main__.worker_task failed with:

Traceback (most recent call last):
File "async_parameter_server.py", line 40, in worker_task
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py", line 245, in read_data_sets
source_url + TRAIN_LABELS)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/base.py", line 209, in maybe_download
gfile.Copy(temp_file_name, filepath)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 385, in copy
compat.as_bytes(oldpath), compat.as_bytes(newpath), overwrite, status)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.AlreadyExistsError: file already exists

# Fixed code
def __init__(self, worker_index, batch_size=50):
    self.worker_index = worker_index
    self.batch_size = batch_size
    self.mnist = model.download_mnist_retry(seed=worker_index)
    self.net = model.SimpleCNN()
# Buggy code
def save(self):
    """Saves the current model state to a checkpoint.

    Returns:
        Checkpoint path that may be passed to restore().
    """

    checkpoint_path = self._save()
    pickle.dump(
        [self.experiment_id, self.iteration, self.timesteps_total, self.time_total_s],
        open(checkpoint_path + ".rllib_metadata", "wb"),
    )
    return checkpoint_path


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-4c879b9f1898> in <module>()
5
6 agent = PPOAgent('Pong-v0', DEFAULT_CONFIG)
----> 7 agent.save()

~/Workspace/ray/python/ray/rllib/common.py in save(self)
171         pickle.dump(
172             [self.experiment_id, self.iteration, self.timesteps_total,
--> 173              self.time_total_s],
174             open(checkpoint_path + ".rllib_metadata", "wb"))
175         return checkpoint_path

AttributeError: 'PPOAgent' object has no attribute 'time_total_s'

# Fixed code
def save(self):
    """Saves the current model state to a checkpoint.

    Returns:
        Checkpoint path that may be passed to restore().
    """

    checkpoint_path = self._save()
    pickle.dump(
        [self.experiment_id, self.iteration, self.timesteps_total, self.time_total],
        open(checkpoint_path + ".rllib_metadata", "wb"),
    )
    return checkpoint_path
# Buggy code
def restore(self, checkpoint_path):
    """Restores training state from a given model checkpoint.

    These checkpoints are returned from calls to save().
    """

    self._restore(checkpoint_path)
    metadata = pickle.load(open(checkpoint_path + ".rllib_metadata", "rb"))
    self.experiment_id = metadata[0]
    self.iteration = metadata[1]
    self.timesteps_total = metadata[2]
    self.time_total_s = metadata[3]


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-4c879b9f1898> in <module>()
5
6 agent = PPOAgent('Pong-v0', DEFAULT_CONFIG)
----> 7 agent.save()

~/Workspace/ray/python/ray/rllib/common.py in save(self)
171         pickle.dump(
172             [self.experiment_id, self.iteration, self.timesteps_total,
--> 173              self.time_total_s],
174             open(checkpoint_path + ".rllib_metadata", "wb"))
175         return checkpoint_path

AttributeError: 'PPOAgent' object has no attribute 'time_total_s'

# Fixed code
def restore(self, checkpoint_path):
    """Restores training state from a given model checkpoint.

    These checkpoints are returned from calls to save().
    """

    self._restore(checkpoint_path)
    metadata = pickle.load(open(checkpoint_path + ".rllib_metadata", "rb"))
    self.experiment_id = metadata[0]
    self.iteration = metadata[1]
    self.timesteps_total = metadata[2]
    self.time_total = metadata[3]
# Buggy code
def is_adhoc_metric(metric: Metric) -> bool:
    if not isinstance(metric, dict):
        return False
    metric = cast(Dict[str, Any], metric)
    return bool(
        (
            (
                metric.get("expressionType") == AdhocMetricExpressionType.SIMPLE
                and metric.get("column")
                and cast(Dict[str, Any], metric["column"]).get("column_name")
                and metric.get("aggregate")
            )
            or (
                metric.get("expressionType") == AdhocMetricExpressionType.SQL
                and metric.get("sqlExpression")
            )
        )
        and metric.get("label")
    )


# Traceback (TypeError)
Sorry, something went wrong
500 - Internal Server Error
Stacktrace
Traceback (most recent call last):
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/flask_appbuilder/security/decorators.py", line 109, in wraps
return f(self, *args, **kwargs)
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/core.py", line 1616, in dashboard
for datasource, slices in datasources.items()
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/views/core.py", line 1616, in <dictcomp>
for datasource, slices in datasources.items()
File "/srv/deployment/analytics/superset/venv/lib/python3.7/site-packages/superset/connectors/base/models.py", line 287, in data_for_slices
metric_names.add(utils.get_metric_name(metric))
TypeError: unhashable type: 'dict'

# Fixed code
def is_adhoc_metric(metric: Metric) -> bool:
    return isinstance(metric, dict)
# Buggy code
def get_url(chart):
    """Return external URL for warming up a given chart/table cache."""
    with app.test_request_context():
        baseurl = "{SUPERSET_WEBSERVER_ADDRESS}:{SUPERSET_WEBSERVER_PORT}".format(
            **app.config
        )
        return f"{baseurl}{chart.url}"


# Traceback (urllib.error.URLError)
[2019-10-28 15:00:00,015: INFO/ForkPoolWorker-6] cache-warmup[4345da24-b272-4af8-a8bc-2c1ee924191c]: Loading strategy
[2019-10-28 15:00:00,015: INFO/ForkPoolWorker-6] cache-warmup[4345da24-b272-4af8-a8bc-2c1ee924191c]: Loading TopNDashboardsStrategy
[2019-10-28 15:00:00,017: INFO/ForkPoolWorker-6] cache-warmup[4345da24-b272-4af8-a8bc-2c1ee924191c]: Success!
[2019-10-28 15:00:00,031: INFO/ForkPoolWorker-6] cache-warmup[4345da24-b272-4af8-a8bc-2c1ee924191c]: Fetching 0.0.0.0:8088/superset/explore/?form_data=%7B%22slice_id%22%3A%201%7D
[2019-10-28 15:00:00,031: ERROR/ForkPoolWorker-6] cache-warmup[4345da24-b272-4af8-a8bc-2c1ee924191c]: Error warming up cache!
Traceback (most recent call last):
File "/home/superset/superset/tasks/cache.py", line 285, in cache_warmup
request.urlopen(url)
File "/usr/local/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/usr/local/lib/python3.6/urllib/request.py", line 549, in _open
'unknown_open', req)
File "/usr/local/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.6/urllib/request.py", line 1388, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: 0.0.0.0>

# Fixed code
def get_url(chart):
    """Return external URL for warming up a given chart/table cache."""
    with app.test_request_context():
        baseurl = (
            "{SUPERSET_WEBSERVER_PROTOCOL}://"
            "{SUPERSET_WEBSERVER_ADDRESS}:"
            "{SUPERSET_WEBSERVER_PORT}".format(**app.config)
        )
        return f"{baseurl}{chart.url}"
# Buggy code
def configure_celery(self) -> None:
    celery_app.config_from_object(self.config["CELERY_CONFIG"])
    celery_app.set_default()


# 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 configure_celery(self) -> None:
    celery_app.config_from_object(self.config["CELERY_CONFIG"])
    celery_app.set_default()
    flask_app = self.flask_app

    # Here, we want to ensure that every call into Celery task has an app context
    # setup properly
    task_base = celery_app.Task

    class AppContextTask(task_base):  # type: ignore
        # pylint: disable=too-few-public-methods
        abstract = True

        # Grab each call into the task and set up an app context
        def __call__(self, *args, **kwargs):
            with flask_app.app_context():
                return task_base.__call__(self, *args, **kwargs)

    celery_app.Task = AppContextTask
# Buggy code
def get_query_backoff_handler(details):
    query_id = details["kwargs"]["query_id"]
    logging.error(f"Query with id `{query_id}` could not be retrieved")
    stats_logger.incr("error_attempting_orm_query_{}".format(details["tries"] - 1))
    logging.error(f"Query {query_id}: Sleeping for a sec before retrying...")


# 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 get_query_backoff_handler(details):
    query_id = details["kwargs"]["query_id"]
    logger.error(f"Query with id `{query_id}` could not be retrieved")
    stats_logger.incr("error_attempting_orm_query_{}".format(details["tries"] - 1))
    logger.error(f"Query {query_id}: Sleeping for a sec before retrying...")