gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _handle_download_error(err, peer, blob_to_download):
    if not err.check(
        DownloadCanceledError, PriceDisagreementError, RequestCanceledError
    ):
        log.warning(
            "An error occurred while downloading %s from %s. Error: %s",
            blob_to_download.blob_hash,
            str(peer),
            err.getTraceback(),
        )
    if err.check(PriceDisagreementError):
        # Don't kill the whole connection just because a price couldn't be agreed upon.
        # Other information might be desired by other request creators at a better rate.
        return True
    return err


# Traceback (exceptions.ValueError)
2017-10-12 13:52:54,172 INFO     lbrynet.core.client.ClientProtocol:185: Closing the connection to x.x.x.x:3333 because the download of blob a5d1ebd863d2b5f7 was canceled
2017-10-12 13:52:54,174 ERROR    lbrynet.core.client.ClientProtocol:130: An unexpected error occurred creating or sending a request to x.x.x.x:3333. Error message: Traceback (most recent call last):
File "site-packages/twisted/internet/defer.py", line 651, in _runCallbacks
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 235, in get_next_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 147, in _ask_for_request
File "site-packages/twisted/internet/defer.py", line 1445, in unwindGenerator
--- <exception caught here> ---
File "site-packages/twisted/internet/defer.py", line 1299, in _inlineCallbacks
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 111, in get_next_request
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 137, in _send_primary_requests
File "site-packages/lbrynet/core/client/BlobRequester.py", line 66, in send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 113, in _send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 440, in make_request_and_handle_response
File "site-packages/lbrynet/core/client/BlobRequester.py", line 493, in _handle_download_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 540, in create_add_blob_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 108, in add_blob_request
exceptions.ValueError: There is already a blob download request active

# Fixed code
def _handle_download_error(err, peer, blob_to_download):
    if not err.check(
        DownloadCanceledError,
        PriceDisagreementError,
        RequestCanceledError,
        ConnectionClosedBeforeResponseError,
    ):
        log.warning(
            "An error occurred while downloading %s from %s. Error: %s",
            blob_to_download.blob_hash,
            str(peer),
            err.getTraceback(),
        )
    if err.check(PriceDisagreementError):
        # Don't kill the whole connection just because a price couldn't be agreed upon.
        # Other information might be desired by other request creators at a better rate.
        return True
    return err
# Buggy code
def add_blob_request(self, blob_request):
    if self._blob_download_request is None:
        d = self.add_request(blob_request)
        self._blob_download_request = blob_request
        blob_request.finished_deferred.addCallbacks(
            self._downloading_finished, self._handle_response_error
        )
        return d
    else:
        raise ValueError("There is already a blob download request active")


# Traceback (exceptions.ValueError)
2017-10-12 13:52:54,172 INFO     lbrynet.core.client.ClientProtocol:185: Closing the connection to x.x.x.x:3333 because the download of blob a5d1ebd863d2b5f7 was canceled
2017-10-12 13:52:54,174 ERROR    lbrynet.core.client.ClientProtocol:130: An unexpected error occurred creating or sending a request to x.x.x.x:3333. Error message: Traceback (most recent call last):
File "site-packages/twisted/internet/defer.py", line 651, in _runCallbacks
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 235, in get_next_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 147, in _ask_for_request
File "site-packages/twisted/internet/defer.py", line 1445, in unwindGenerator
--- <exception caught here> ---
File "site-packages/twisted/internet/defer.py", line 1299, in _inlineCallbacks
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 111, in get_next_request
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 137, in _send_primary_requests
File "site-packages/lbrynet/core/client/BlobRequester.py", line 66, in send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 113, in _send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 440, in make_request_and_handle_response
File "site-packages/lbrynet/core/client/BlobRequester.py", line 493, in _handle_download_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 540, in create_add_blob_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 108, in add_blob_request
exceptions.ValueError: There is already a blob download request active

# Fixed code
def add_blob_request(self, blob_request):
    if self._blob_download_request is None:
        d = self.add_request(blob_request)
        self._blob_download_request = blob_request
        blob_request.finished_deferred.addCallbacks(
            self._downloading_finished, self._handle_response_error
        )
        return d
    else:
        return defer.fail(ValueError("There is already a blob download request active"))
# Buggy code
def _handle_request_error(self, err):
    log.error(
        "An unexpected error occurred creating or sending a request to %s. Error message: %s",
        self.peer,
        err.getTraceback(),
    )
    self.transport.loseConnection()


# Traceback (exceptions.ValueError)
2017-10-12 13:52:54,172 INFO     lbrynet.core.client.ClientProtocol:185: Closing the connection to x.x.x.x:3333 because the download of blob a5d1ebd863d2b5f7 was canceled
2017-10-12 13:52:54,174 ERROR    lbrynet.core.client.ClientProtocol:130: An unexpected error occurred creating or sending a request to x.x.x.x:3333. Error message: Traceback (most recent call last):
File "site-packages/twisted/internet/defer.py", line 651, in _runCallbacks
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 235, in get_next_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 147, in _ask_for_request
File "site-packages/twisted/internet/defer.py", line 1445, in unwindGenerator
--- <exception caught here> ---
File "site-packages/twisted/internet/defer.py", line 1299, in _inlineCallbacks
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 111, in get_next_request
File "site-packages/lbrynet/core/client/ConnectionManager.py", line 137, in _send_primary_requests
File "site-packages/lbrynet/core/client/BlobRequester.py", line 66, in send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 113, in _send_next_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 440, in make_request_and_handle_response
File "site-packages/lbrynet/core/client/BlobRequester.py", line 493, in _handle_download_request
File "site-packages/lbrynet/core/client/BlobRequester.py", line 540, in create_add_blob_request
File "site-packages/lbrynet/core/client/ClientProtocol.py", line 108, in add_blob_request
exceptions.ValueError: There is already a blob download request active

# Fixed code
def _handle_request_error(self, err):
    log.error(
        "An unexpected error occurred creating or sending a request to %s. %s: %s",
        self.peer,
        err.type,
        err.message,
    )
    self.transport.loseConnection()
# Buggy code
def check_connection(server="lbry.io", port=80):
    """Attempts to open a socket to server:port and returns True if successful."""
    try:
        log.debug("Checking connection to %s:%s", server, port)
        host = socket.gethostbyname(server)
        s = socket.create_connection((host, port), 2)
        log.debug("Connection successful")
        return True
    except Exception as ex:
        log.info(
            "Failed to connect to %s:%s. Maybe the internet connection is not working",
            server,
            port,
            exc_info=True,
        )
        return False


# Traceback (gaierror)
$ /opt/lbry/lbrynet-daemon --version
{
"build": "release",
"installation_id": "5GfsGqN89ysnaQiorZZNg3P3vDbc5WWJ75FbNDEiCoZXpzE4beznwMTHbNPYLww8gA",
"lbrynet_version": "0.16.0",
"lbryschema_version": "0.0.11",
"lbryum_version": "3.1.7",
"os_release": "4.4.0-93-generic",
"os_system": "Linux",
"platform": "Linux-4.4.0-93-generic-x86_64-with-Ubuntu-16.04-xenial",
"processor": "x86_64",
"python_version": "2.7.12"
}
$ /opt/lbry/lbrynet-daemon
2017-09-20 13:40:34,369 INFO     lbrynet.daemon.DaemonControl:70: Starting lbrynet-daemon from command line
2017-09-20 13:40:34,373 INFO     lbrynet.core.utils:108: Failed to connect to lbry.io:80. Maybe the internet connection is not working
Traceback (most recent call last):
File "site-packages/lbrynet/core/utils.py", line 101, in check_connection
gaierror: [Errno -2] Name or service not known
2017-09-20 13:40:34,374 INFO     lbrynet.daemon.DaemonControl:77: Not connected to internet, unable to start

# Fixed code
def check_connection(server="lbry.io", port=80, timeout=2, bypass_dns=False):
    """Attempts to open a socket to server:port and returns True if successful."""
    log.debug("Checking connection to %s:%s", server, port)
    try:
        if not bypass_dns:
            server = socket.gethostbyname(server)
        socket.create_connection((server, port), timeout)
        log.debug("Connection successful")
        return True
    except (socket.gaierror, socket.herror) as ex:
        log.info(
            "Failed to connect to %s:%s. Unable to resolve domain. Trying to bypass DNS",
            server,
            port,
            exc_info=True,
        )
        try:
            server = "8.8.8.8"
            port = 53
            socket.create_connection((server, port), timeout)
            log.debug("Connection successful")
            return True
        except Exception as ex:
            log.info(
                "Failed to connect to %s:%s. Maybe the internet connection is not working",
                server,
                port,
                exc_info=True,
            )
            return False
    except Exception as ex:
        log.info(
            "Failed to connect to %s:%s. Maybe the internet connection is not working",
            server,
            port,
            exc_info=True,
        )
        return False
# Buggy code
def _load_start_paths(self):
    "Start the Read-Eval-Print Loop."
    if self._startup_paths:
        for path in self._startup_paths:
            if os.path.exists(path):
                with open(path, "r") as f:
                    code = compile(f.read(), path, "exec")
                    six.exec_(code, self.get_globals(), self.get_locals())
            else:
                output = self.app.output
                output.write("WARNING | File not found: {}\n\n".format(path))


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\Scripts\ptpython.exe\__main__.py", line 9, in <module>
File "c:\python36\lib\site-packages\ptpython\entry_points\run_ptpython.py", line 74, in run
title='Python REPL (ptpython)')
File "c:\python36\lib\site-packages\ptpython\repl.py", line 320, in embed
cli.run()
File "c:\python36\lib\site-packages\prompt_toolkit\interface.py", line 404, in run
self.on_start.fire()
File "c:\python36\lib\site-packages\prompt_toolkit\utils.py", line 60, in fire
self()
File "c:\python36\lib\site-packages\prompt_toolkit\utils.py", line 56, in __call__
handler(self.sender)
File "c:\python36\lib\site-packages\ptpython\repl.py", line 62, in _on_start
code = compile(f.read(), path, 'exec')
File "c:\python36\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2: character maps to <undefined>

# Fixed code
def _load_start_paths(self):
    "Start the Read-Eval-Print Loop."
    if self._startup_paths:
        for path in self._startup_paths:
            if os.path.exists(path):
                with open(path, "rb") as f:
                    code = compile(f.read(), path, "exec")
                    six.exec_(code, self.get_globals(), self.get_locals())
            else:
                output = self.app.output
                output.write("WARNING | File not found: {}\n\n".format(path))
# Buggy code
def predict_proba(self, X, batch_size=None, n_jobs=1):
    return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)


# Traceback (AttributeError)
AttributeError                            Traceback (most recent call last)
<ipython-input-257-a782d97ebce8> in <module>()
----> 1 pipe.predict_proba(clf_x[te_idx])

~/repos/vcf/research/env/lib/python3.5/site-packages/autosklearn/estimators.py in predict_proba(self, X, batch_size, n_jobs)
430         """
431         return self._automl.predict_proba(
--> 432             X, batch_size=batch_size, n_jobs=n_jobs)
433
434

~/repos/vcf/research/env/lib/python3.5/site-packages/autosklearn/automl.py in predict_proba(self, X, batch_size, n_jobs)
944
945     def predict_proba(self, X, batch_size=None, n_jobs=1):
--> 946         return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)
947
948

AttributeError: 'AutoMLClassifier' object has no attribute '_automl'

# Fixed code
def predict_proba(self, X, batch_size=None, n_jobs=1):
    return super().predict(X, batch_size=batch_size, n_jobs=n_jobs)
# Buggy code
def predict_proba(self, X, batch_size=None, n_jobs=1):
    """Predict probabilities of classes for all samples X.

    Parameters
    ----------
    X : array-like or sparse matrix of shape = [n_samples, n_features]

    Returns
    -------
    y : array of shape = [n_samples, n_classes] or [n_samples, n_labels]
        The predicted class probabilities.

    """
    return self._automl.predict_proba(X, batch_size=batch_size, n_jobs=n_jobs)


# Traceback (AttributeError)
AttributeError                            Traceback (most recent call last)
<ipython-input-257-a782d97ebce8> in <module>()
----> 1 pipe.predict_proba(clf_x[te_idx])

~/repos/vcf/research/env/lib/python3.5/site-packages/autosklearn/estimators.py in predict_proba(self, X, batch_size, n_jobs)
430         """
431         return self._automl.predict_proba(
--> 432             X, batch_size=batch_size, n_jobs=n_jobs)
433
434

~/repos/vcf/research/env/lib/python3.5/site-packages/autosklearn/automl.py in predict_proba(self, X, batch_size, n_jobs)
944
945     def predict_proba(self, X, batch_size=None, n_jobs=1):
--> 946         return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)
947
948

AttributeError: 'AutoMLClassifier' object has no attribute '_automl'

# Fixed code
def predict_proba(self, X, batch_size=None, n_jobs=1):
    """Predict probabilities of classes for all samples X.

    Parameters
    ----------
    X : array-like or sparse matrix of shape = [n_samples, n_features]

    Returns
    -------
    y : array of shape = [n_samples, n_classes] or [n_samples, n_labels]
        The predicted class probabilities.

    """
    return super().predict_proba(X, batch_size=batch_size, n_jobs=n_jobs)
# Buggy code
def rmdir(self, path=None):
    path = normalize_storage_path(path)
    if path:
        with self.lock:
            self.cursor.execute('DELETE FROM zarr WHERE k LIKE (? || "_%")', (path,))
    else:
        self.clear()


# Traceback (builtins.KeyError)
import zarr
import numpy as np

path = 'D:/test.db'
store = zarr.SQLiteStore(path)
group = zarr.open_group(store)
group.array('prefix', np.arange(1000))
group.array('prefix_suffix', np.arange(100))
group['prefix_suffix']
Traceback (most recent call last):
Python Shell, prompt 3, line 1
# Used internally for debug sandbox under external interpreter
File "d:\Program\Anaconda3\envs\dev\Lib\site-packages\zarr\hierarchy.py", line 333, in __getitem__
raise KeyError(item)
builtins.KeyError: 'prefix_suffix'

# Fixed code
def rmdir(self, path=None):
    path = normalize_storage_path(path)
    if path:
        with self.lock:
            self.cursor.execute('DELETE FROM zarr WHERE k LIKE (? || "/%")', (path,))
    else:
        self.clear()
# Buggy code
def listdir(self, path=None):
    path = normalize_storage_path(path)
    keys = self.cursor.execute(
        """
            SELECT DISTINCT SUBSTR(m, 0, INSTR(m, "/")) AS l FROM (
                SELECT LTRIM(SUBSTR(k, LENGTH(?) + 1), "/") || "/" AS m
                FROM zarr WHERE k LIKE (? || "_%")
            ) ORDER BY l ASC
            """,
        (path, path),
    )
    keys = list(map(operator.itemgetter(0), keys))
    return keys


# Traceback (builtins.KeyError)
import zarr
import numpy as np

path = 'D:/test.db'
store = zarr.SQLiteStore(path)
group = zarr.open_group(store)
group.array('prefix', np.arange(1000))
group.array('prefix_suffix', np.arange(100))
group['prefix_suffix']
Traceback (most recent call last):
Python Shell, prompt 3, line 1
# Used internally for debug sandbox under external interpreter
File "d:\Program\Anaconda3\envs\dev\Lib\site-packages\zarr\hierarchy.py", line 333, in __getitem__
raise KeyError(item)
builtins.KeyError: 'prefix_suffix'

# Fixed code
def listdir(self, path=None):
    path = normalize_storage_path(path)
    sep = "_" if path == "" else "/"
    keys = self.cursor.execute(
        """
            SELECT DISTINCT SUBSTR(m, 0, INSTR(m, "/")) AS l FROM (
                SELECT LTRIM(SUBSTR(k, LENGTH(?) + 1), "/") || "/" AS m
                FROM zarr WHERE k LIKE (? || "{sep}%")
            ) ORDER BY l ASC
            """.format(sep=sep),
        (path, path),
    )
    keys = list(map(operator.itemgetter(0), keys))
    return keys
# Buggy code
def _encode_chunk(self, chunk):
    # apply filters
    if self._filters:
        for f in self._filters:
            chunk = f.encode(chunk)

    # check object encoding
    if isinstance(chunk, np.ndarray) and chunk.dtype == object:
        raise RuntimeError("cannot write object array without object codec")

    # compress
    if self._compressor:
        cdata = self._compressor.encode(chunk)
    else:
        cdata = chunk

    return cdata


# Traceback (ValueError)
In [1]: import zarr

In [2]: z1 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)

In [3]: z2 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)

In [4]: z1 == z2
Out[4]: True

In [5]: z1[0] = 5

In [6]: z2[0] = 5

In [7]: z1 == z2
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-4176b4e1c607> in <module>
----> 1 z1 == z2

/zopt/conda3/envs/test_zarr/lib/python3.6/site-packages/zarr/core.py in __eq__(self, other)
410         return (
411             isinstance(other, Array) and
--> 412             self.store == other.store and
413             self.read_only == other.read_only and
414             self.path == other.path and

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

# Fixed code
def _encode_chunk(self, chunk):
    # apply filters
    if self._filters:
        for f in self._filters:
            chunk = f.encode(chunk)

    # check object encoding
    if isinstance(chunk, np.ndarray) and chunk.dtype == object:
        raise RuntimeError("cannot write object array without object codec")

    # compress
    if self._compressor:
        cdata = self._compressor.encode(chunk)
    else:
        cdata = chunk

    # ensure in-memory data is immutable and easy to compare
    if isinstance(self.chunk_store, dict):
        cdata = ensure_bytes(cdata)

    return cdata
# Buggy code
def __setitem__(self, item, value):
    with self.write_mutex:
        parent, key = self._require_parent(item)
        parent[key] = value


# Traceback (ValueError)
In [1]: import zarr

In [2]: z1 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)

In [3]: z2 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)

In [4]: z1 == z2
Out[4]: True

In [5]: z1[0] = 5

In [6]: z2[0] = 5

In [7]: z1 == z2
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-4176b4e1c607> in <module>
----> 1 z1 == z2

/zopt/conda3/envs/test_zarr/lib/python3.6/site-packages/zarr/core.py in __eq__(self, other)
410         return (
411             isinstance(other, Array) and
--> 412             self.store == other.store and
413             self.read_only == other.read_only and
414             self.path == other.path and

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

# Fixed code
def __setitem__(self, item, value):
    with self.write_mutex:
        parent, key = self._require_parent(item)
        value = ensure_bytes(value)
        parent[key] = value
# Buggy code
def getsize(self, path=None):
    path = normalize_storage_path(path)

    # obtain value to return size of
    value = None
    if path:
        try:
            parent, key = self._get_parent(path)
            value = parent[key]
        except KeyError:
            pass
    else:
        value = self.root

    # obtain size of value
    if value is None:
        return 0

    elif isinstance(value, self.cls):
        # total size for directory
        size = 0
        for v in value.values():
            if not isinstance(v, self.cls):
                try:
                    size += buffer_size(v)
                except TypeError:
                    return -1
        return size

    else:
        try:
            return buffer_size(value)
        except TypeError:
            return -1


# Traceback (ValueError)
In [1]: import zarr

In [2]: z1 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)

In [3]: z2 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)

In [4]: z1 == z2
Out[4]: True

In [5]: z1[0] = 5

In [6]: z2[0] = 5

In [7]: z1 == z2
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-4176b4e1c607> in <module>
----> 1 z1 == z2

/zopt/conda3/envs/test_zarr/lib/python3.6/site-packages/zarr/core.py in __eq__(self, other)
410         return (
411             isinstance(other, Array) and
--> 412             self.store == other.store and
413             self.read_only == other.read_only and
414             self.path == other.path and

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

# Fixed code
def getsize(self, path=None):
    path = normalize_storage_path(path)

    # obtain value to return size of
    value = None
    if path:
        try:
            parent, key = self._get_parent(path)
            value = parent[key]
        except KeyError:
            pass
    else:
        value = self.root

    # obtain size of value
    if value is None:
        return 0

    elif isinstance(value, self.cls):
        # total size for directory
        size = 0
        for v in value.values():
            if not isinstance(v, self.cls):
                size += buffer_size(v)
        return size

    else:
        return buffer_size(value)
# Buggy code
def shutdown_agents(opts):
    opts.connection.call("shutdown")
    _log.debug("Calling stop_platform")
    if opts.platform:
        opts.connection.notify("stop_platform")


# Traceback (AttributeError)
Shutting down VOLTTRON
Traceback (most recent call last):
File "/home/osboxes/repos/pr-test/env/local/lib/python2.7/site-packages/gevent/greenlet.py", line 534, in run
result = self._run(*self.args, **self.kwargs)
File "/home/osboxes/repos/pr-test/volttron/platform/vip/agent/core.py", line 276, in run
looper.next()
File "/home/osboxes/repos/pr-test/volttron/platform/vip/agent/core.py", line 888, in loop
param = self._build_connection_parameters()
File "/home/osboxes/repos/pr-test/volttron/platform/vip/agent/core.py", line 883, in _build_connection_parameters
self.instance_name)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 876, in build_agent_connection
self.create_user_with_permissions(rmq_user, permissions, ssl_auth=self.is_ssl)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 847, in create_user_with_permissions
if user not in self.get_users(ssl_auth):
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 248, in get_users
response = self._http_get_request(url, ssl_auth)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 163, in _http_get_request
response = self._call_grequest('get', url, ssl_auth)
File "/home/osboxes/repos/pr-test/volttron/utils/rmq_mgmt.py", line 116, in _call_grequest
raise e
AttributeError: 'NoneType' object has no attribute 'raise_for_status'
<Greenlet at 0x7ff71ca50eb0: <bound method RMQCore.run of <volttron.platform.vip.agent.core.RMQCore object at 0x7ff71c976f50>>(<gevent.event.Event object at 0x7ff71c9685d0>)> failed with AttributeError

# Fixed code
def shutdown_agents(opts):
    if "rmq" == utils.get_messagebus() and not check_rabbit_status():
        opts.aip.rmq_shutdown()
    else:
        opts.connection.call("shutdown")
        _log.debug("Calling stop_platform")
        if opts.platform:
            opts.connection.notify("stop_platform")
# Buggy code
def __init__(
    self,
    destination_vip,
    destination_serverkey,
    destination_historian_identity=PLATFORM_HISTORIAN,
    **kwargs,
):
    """

    :param destination_vip: vip address of the destination volttron
    instance
    :param destination_serverkey: public key of the destination server
    :param services_topic_list: subset of topics that are inherently
    supported by base historian. Default is device, analysis, logger,
    and record topics
    :param custom_topic_list: any additional topics this historian
    should subscribe to.
    :param destination_historian_identity: vip identity of the
    destination historian. default is 'platform.historian'
    :param kwargs: additional arguments to be passed along to parent class
    """

    super(DataMover, self).__init__(**kwargs)
    self.destination_vip = destination_vip
    self.destination_serverkey = destination_serverkey
    self.destination_historian_identity = destination_historian_identity

    config = {
        "destination_vip": self.destination_vip,
        "destination_serverkey": self.destination_serverkey,
        "destination_historian_identity": self.destination_historian_identity,
    }

    self.update_default_config(config)

    # will be available in both threads.
    self._last_timeout = 0


# Traceback (KeyError)
('RPC ERROR', 'Traceback (most recent call last):
File "/home/jer/git/volttron-craig/volttron/platform/vip/agent/subsystems/rpc.py", line 169, in method
return method(*args, **kwargs)
File "/home/jer/git/volttron-craig/volttron/platform/store.py", line 256, in manage_get_metadata
raise KeyError(\'No configuration file "{}" for VIP IDENTIY {}\'.format(config_name, identity))
KeyError: \'No configuration file "config" for VIP IDENTIY forwarder2\'\n')

# Fixed code
def __init__(
    self,
    destination_vip,
    destination_serverkey,
    destination_historian_identity=PLATFORM_HISTORIAN,
    **kwargs,
):
    """

    :param destination_vip: vip address of the destination volttron
    instance
    :param destination_serverkey: public key of the destination server
    :param services_topic_list: subset of topics that are inherently
    supported by base historian. Default is device, analysis, logger,
    and record topics
    :param custom_topic_list: any additional topics this historian
    should subscribe to.
    :param destination_historian_identity: vip identity of the
    destination historian. default is 'platform.historian'
    :param kwargs: additional arguments to be passed along to parent class
    """
    kwargs["process_loop_in_greenlet"] = True
    super(DataMover, self).__init__(**kwargs)
    self.destination_vip = destination_vip
    self.destination_serverkey = destination_serverkey
    self.destination_historian_identity = destination_historian_identity

    config = {
        "destination_vip": self.destination_vip,
        "destination_serverkey": self.destination_serverkey,
        "destination_historian_identity": self.destination_historian_identity,
    }

    self.update_default_config(config)

    # will be available in both threads.
    self._last_timeout = 0
# Buggy code
def __init__(
    self,
    destination_vip,
    destination_serverkey,
    custom_topic_list=[],
    topic_replace_list=[],
    required_target_agents=[],
    cache_only=False,
    **kwargs,
):
    super(ForwardHistorian, self).__init__(**kwargs)

    # will be available in both threads.
    self._topic_replace_map = {}
    self.topic_replace_list = topic_replace_list
    self._num_failures = 0
    self._last_timeout = 0
    self._target_platform = None
    self._current_custom_topics = set()
    self.destination_vip = destination_vip
    self.destination_serverkey = destination_serverkey
    self.required_target_agents = required_target_agents
    self.cache_only = cache_only

    config = {
        "custom_topic_list": custom_topic_list,
        "topic_replace_list": self.topic_replace_list,
        "required_target_agents": self.required_target_agents,
        "destination_vip": self.destination_vip,
        "destination_serverkey": self.destination_serverkey,
        "cache_only": self.cache_only,
    }

    self.update_default_config(config)

    # We do not support the insert RPC call.
    self.no_insert = True
    # We do not support the query RPC call.
    self.no_query = True


# Traceback (KeyError)
('RPC ERROR', 'Traceback (most recent call last):
File "/home/jer/git/volttron-craig/volttron/platform/vip/agent/subsystems/rpc.py", line 169, in method
return method(*args, **kwargs)
File "/home/jer/git/volttron-craig/volttron/platform/store.py", line 256, in manage_get_metadata
raise KeyError(\'No configuration file "{}" for VIP IDENTIY {}\'.format(config_name, identity))
KeyError: \'No configuration file "config" for VIP IDENTIY forwarder2\'\n')

# Fixed code
def __init__(
    self,
    destination_vip,
    destination_serverkey,
    custom_topic_list=[],
    topic_replace_list=[],
    required_target_agents=[],
    cache_only=False,
    **kwargs,
):
    kwargs["process_loop_in_greenlet"] = True
    super(ForwardHistorian, self).__init__(**kwargs)

    # will be available in both threads.
    self._topic_replace_map = {}
    self.topic_replace_list = topic_replace_list
    self._num_failures = 0
    self._last_timeout = 0
    self._target_platform = None
    self._current_custom_topics = set()
    self.destination_vip = destination_vip
    self.destination_serverkey = destination_serverkey
    self.required_target_agents = required_target_agents
    self.cache_only = cache_only

    config = {
        "custom_topic_list": custom_topic_list,
        "topic_replace_list": self.topic_replace_list,
        "required_target_agents": self.required_target_agents,
        "destination_vip": self.destination_vip,
        "destination_serverkey": self.destination_serverkey,
        "cache_only": self.cache_only,
    }

    self.update_default_config(config)

    # We do not support the insert RPC call.
    self.no_insert = True
    # We do not support the query RPC call.
    self.no_query = True
# Buggy code
def start_process_thread(self):
    self._process_thread = Thread(target=self._process_loop)
    self._process_thread.daemon = True  # Don't wait on thread to exit.
    self._process_thread.start()
    _log.debug("Process thread started.")


# Traceback (KeyError)
('RPC ERROR', 'Traceback (most recent call last):
File "/home/jer/git/volttron-craig/volttron/platform/vip/agent/subsystems/rpc.py", line 169, in method
return method(*args, **kwargs)
File "/home/jer/git/volttron-craig/volttron/platform/store.py", line 256, in manage_get_metadata
raise KeyError(\'No configuration file "{}" for VIP IDENTIY {}\'.format(config_name, identity))
KeyError: \'No configuration file "config" for VIP IDENTIY forwarder2\'\n')

# Fixed code
def start_process_thread(self):
    if self._process_loop_in_greenlet:
        self._process_thread = self.core.spawn(self._process_loop)
        self._process_thread.start()
        _log.debug("Process greenlet started.")
    else:
        self._process_thread = Thread(target=self._process_loop)
        self._process_thread.daemon = True  # Don't wait on thread to exit.
        self._process_thread.start()
        _log.debug("Process thread started.")
# Buggy code
def stop_process_thread(self):
    _log.debug("Stopping the process thread.")
    if self._process_thread is None:
        return

    # Tell the loop it needs to die.
    self._stop_process_loop = True
    # Wake the loop.
    self._event_queue.put(None)

    # 9 seconds as configuration timeout is 10 seconds.
    self._process_thread.join(9.0)
    if self._process_thread.is_alive():
        _log.error("Failed to stop process thread during reconfiguration!")

    self._process_thread = None
    _log.debug("Process thread stopped.")


# Traceback (KeyError)
('RPC ERROR', 'Traceback (most recent call last):
File "/home/jer/git/volttron-craig/volttron/platform/vip/agent/subsystems/rpc.py", line 169, in method
return method(*args, **kwargs)
File "/home/jer/git/volttron-craig/volttron/platform/store.py", line 256, in manage_get_metadata
raise KeyError(\'No configuration file "{}" for VIP IDENTIY {}\'.format(config_name, identity))
KeyError: \'No configuration file "config" for VIP IDENTIY forwarder2\'\n')

# Fixed code
def stop_process_thread(self):
    _log.debug("Stopping the process loop.")
    if self._process_thread is None:
        return

    # Tell the loop it needs to die.
    self._stop_process_loop = True
    # Wake the loop.
    self._event_queue.put(None)

    # 9 seconds as configuration timeout is 10 seconds.
    self._process_thread.join(9.0)
    # Greenlets have slightly different API than threads in this case.
    if self._process_loop_in_greenlet:
        if not self._process_thread.ready():
            _log.error("Failed to stop process greenlet during reconfiguration!")
    elif self._process_thread.is_alive():
        _log.error("Failed to stop process thread during reconfiguration!")

    self._process_thread = None
    _log.debug("Process loop stopped.")
# Buggy code
def __init__(self, owner, backup_storage_limit_gb):
    # The topic cache is only meant as a local lookup and should not be
    # accessed via the implemented historians.
    self._backup_cache = {}
    self._meta_data = defaultdict(dict)
    self._owner = weakref.ref(owner)
    self._backup_storage_limit_gb = backup_storage_limit_gb
    self._setupdb()


# Traceback (KeyError)
('RPC ERROR', 'Traceback (most recent call last):
File "/home/jer/git/volttron-craig/volttron/platform/vip/agent/subsystems/rpc.py", line 169, in method
return method(*args, **kwargs)
File "/home/jer/git/volttron-craig/volttron/platform/store.py", line 256, in manage_get_metadata
raise KeyError(\'No configuration file "{}" for VIP IDENTIY {}\'.format(config_name, identity))
KeyError: \'No configuration file "config" for VIP IDENTIY forwarder2\'\n')

# Fixed code
def __init__(self, owner, backup_storage_limit_gb, check_same_thread=True):
    # The topic cache is only meant as a local lookup and should not be
    # accessed via the implemented historians.
    self._backup_cache = {}
    self._meta_data = defaultdict(dict)
    self._owner = weakref.ref(owner)
    self._backup_storage_limit_gb = backup_storage_limit_gb
    self._connection = None
    self._setupdb(check_same_thread)
# Buggy code
def close(self):
    self._connection.close()


# Traceback (KeyError)
('RPC ERROR', 'Traceback (most recent call last):
File "/home/jer/git/volttron-craig/volttron/platform/vip/agent/subsystems/rpc.py", line 169, in method
return method(*args, **kwargs)
File "/home/jer/git/volttron-craig/volttron/platform/store.py", line 256, in manage_get_metadata
raise KeyError(\'No configuration file "{}" for VIP IDENTIY {}\'.format(config_name, identity))
KeyError: \'No configuration file "config" for VIP IDENTIY forwarder2\'\n')

# Fixed code
def close(self):
    self._connection.close()
    self._connection = None
# Buggy code
def historian_setup(self):
    thread_name = threading.currentThread().getName()
    _log.debug("historian_setup on Thread: {}".format(thread_name))


# Traceback (AttributeError)
2016-10-26 15:44:11,091 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR: Exception in thread Thread-2:
2016-10-26 15:44:11,091 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR: Traceback (most recent call last):
2016-10-26 15:44:11,091 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:   File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
2016-10-26 15:44:11,091 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:     self.run()
2016-10-26 15:44:11,091 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:   File "/usr/lib/python2.7/threading.py", line 754, in run
2016-10-26 15:44:11,091 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:     self.__target(*self.__args, **self.__kwargs)
2016-10-26 15:44:11,091 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:   File "/home/building-testbed/volttron4-latest/volttron/platform/agent/base_historian.py", line 639, in _process_loop
2016-10-26 15:44:11,092 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:     self.record_table_definitions(self.volttron_table_defs)
2016-10-26 15:44:11,092 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:   File "/home/building-testbed/.volttron/agents/26d7b095-9e5d-43df-bdfa-7c551584efd0/sqlhistorianagent-3.6.0/sqlhistorian/historian.py", line 192, in record_table_definitions
2016-10-26 15:44:11,092 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR:     self.writer.record_table_definitions(self.tables_def,
2016-10-26 15:44:11,092 (sqlhistorianagent-3.6.0 1179) <stderr> ERROR: AttributeError: 'SQLHistorian' object has no attribute 'writer'

# Fixed code
def historian_setup(self):
    thread_name = threading.currentThread().getName()
    _log.debug("historian_setup on Thread: {}".format(thread_name))

    database_type = self.config["connection"]["type"]
    self.tables_def, table_names = self.parse_table_def(self.config)
    db_functs_class = sqlutils.get_dbfuncts_class(database_type)
    self.reader = db_functs_class(self.config["connection"]["params"], table_names)
    self.writer = db_functs_class(self.config["connection"]["params"], table_names)
    self.reader.setup_historian_tables()

    topic_id_map, topic_name_map = self.reader.get_topic_map()
    self.topic_id_map.update(topic_id_map)
    self.topic_name_map.update(topic_name_map)
    self.agg_topic_id_map = self.reader.get_agg_topic_map()
# Buggy code
def main(database):
    history = History()
    connection = sqlite3.connect(database)

    while True:
        try:
            text = get_input(
                "> ",
                lexer=SqlLexer,
                completer=sql_completer,
                style=DocumentStyle,
                history=history,
                on_abort=AbortAction.RETRY,
            )
        except EOFError:
            break  # Control-D pressed.

        with connection:
            try:
                messages = connection.execute(text)
            except Exception as e:
                print(repr(e))
            else:
                for message in messages:
                    print(message)
    print("GoodBye!")


# Traceback (TypeError)
Traceback (most recent call last):
File "sqlite-cli.py", line 55, in <module>
main(db)
File "sqlite-cli.py", line 29, in main
history = History()
TypeError: Can't instantiate abstract class History with abstract methods __getitem__, __len__, append

# Fixed code
def main(database):
    history = InMemoryHistory()
    connection = sqlite3.connect(database)

    while True:
        try:
            text = get_input(
                "> ",
                lexer=SqlLexer,
                completer=sql_completer,
                style=DocumentStyle,
                history=history,
                on_abort=AbortAction.RETRY,
            )
        except EOFError:
            break  # Control-D pressed.

        with connection:
            try:
                messages = connection.execute(text)
            except Exception as e:
                print(repr(e))
            else:
                for message in messages:
                    print(message)
    print("GoodBye!")
# Buggy code
def get_completions(self, document):
    """Ask jedi to complete."""
    script = get_jedi_script_from_document(
        document, self.get_locals(), self.get_globals()
    )

    if script:
        for c in script.completions():
            yield Completion(
                c.name_with_symbols,
                len(c.complete) - len(c.name_with_symbols),
                display=c.name_with_symbols,
            )


# Traceback (TypeError)
In [1]: for i in range)Exception in thread Thread-13:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "build/bdist.linux-x86_64/egg/prompt_toolkit/__init__.py", line 200, in run
callback()
File "build/bdist.linux-x86_64/egg/prompt_toolkit/__init__.py", line 440, in run
completions = list(line.completer.get_completions(document))
File "build/bdist.linux-x86_64/egg/prompt_toolkit/contrib/python_input.py", line 449, in get_completions
for c in script.completions():
File "/home/cj/.local/lib/python2.7/site-packages/jedi-0.8.1_final0-py2.7.egg/jedi/api/__init__.py", line 187, in completions
new = classes.Completion(self._evaluator, c, needs_dot, len(like), s)
File "/home/cj/.local/lib/python2.7/site-packages/jedi-0.8.1_final0-py2.7.egg/jedi/api/classes.py", line 375, in __init__
super(Completion, self).__init__(evaluator, name.parent, name.start_pos)
File "/home/cj/.local/lib/python2.7/site-packages/jedi-0.8.1_final0-py2.7.egg/jedi/cache.py", line 139, in wrapper
result = func(self)
File "/home/cj/.local/lib/python2.7/site-packages/jedi-0.8.1_final0-py2.7.egg/jedi/api/interpreter.py", line 69, in parent
module = __import__(module_name)
TypeError: __import__() argument 1 must be string, not None

# Fixed code
def get_completions(self, document):
    """Ask jedi to complete."""
    script = get_jedi_script_from_document(
        document, self.get_locals(), self.get_globals()
    )

    if script:
        try:
            completions = script.completions()
        except TypeError:
            # Issue #9: bad syntax causes completions() to fail in jedi.
            # https://github.com/jonathanslenders/python-prompt-toolkit/issues/9
            pass
        else:
            for c in completions:
                yield Completion(
                    c.name_with_symbols,
                    len(c.complete) - len(c.name_with_symbols),
                    display=c.name_with_symbols,
                )
# Buggy code
def __init__(self, image_crs=None, map_crs=None):
    self.image_crs = image_crs
    self.map_crs = map_crs


# Traceback (AttributeError)
root@122d4f0150f4:/opt/data/mar5# rastervision predict spacenet.zip example.jpg out.tif
/usr/local/lib/python3.5/dist-packages/pluginbase.py:439: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
fromlist, level)
2019-03-06 16:59:56.502396: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
/usr/local/lib/python3.5/dist-packages/rasterio/__init__.py:217: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
s = DatasetReader(path, driver=driver, **kwargs)
[0, 1, 2]
2019-03-06 16:59:56:rastervision.task.semantic_segmentation: INFO - Making predictions for scene
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision/__main__.py", line 17, in <module>
rv.main()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision/cli/main.py", line 241, in predict
predictor.predict(image_uri, output_uri, export_config)
File "/opt/src/rastervision/predictor.py", line 144, in predict
scene.prediction_label_store.save(labels)
File "/opt/src/rastervision/data/label_store/semantic_segmentation_raster_store.py", line 90, in save
transform = self.crs_transformer.transform
AttributeError: 'IdentityCRSTransformer' object has no attribute 'transform'

# Fixed code
def __init__(self, image_crs=None, map_crs=None, transform=None):
    self.image_crs = image_crs
    self.map_crs = map_crs
    self.transform = transform
# Buggy code
def get_affine_transform(self):
    raise NotImplementedError()


# Traceback (AttributeError)
root@122d4f0150f4:/opt/data/mar5# rastervision predict spacenet.zip example.jpg out.tif
/usr/local/lib/python3.5/dist-packages/pluginbase.py:439: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
fromlist, level)
2019-03-06 16:59:56.502396: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
/usr/local/lib/python3.5/dist-packages/rasterio/__init__.py:217: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
s = DatasetReader(path, driver=driver, **kwargs)
[0, 1, 2]
2019-03-06 16:59:56:rastervision.task.semantic_segmentation: INFO - Making predictions for scene
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision/__main__.py", line 17, in <module>
rv.main()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision/cli/main.py", line 241, in predict
predictor.predict(image_uri, output_uri, export_config)
File "/opt/src/rastervision/predictor.py", line 144, in predict
scene.prediction_label_store.save(labels)
File "/opt/src/rastervision/data/label_store/semantic_segmentation_raster_store.py", line 90, in save
transform = self.crs_transformer.transform
AttributeError: 'IdentityCRSTransformer' object has no attribute 'transform'

# Fixed code
def get_affine_transform(self):
    return self.transform