gurudesh/pytracebugs huggingface dataset:
# Buggy code
def reduction(a, axis=None, dtype=None, out=None, keepdims=False):
    if out is not None:
        raise ValueError("reduction does not support `out` argument.")

    a = a if isinstance(a, ndarray) else asarray(a)
    dims = _reduction_dims(a, axis)
    result_dtype = _dtype(np_fun(onp.ones((), dtype=dtype or _dtype(a))))
    if _dtype(a) != result_dtype:
        a = lax.convert_element_type(a, result_dtype)
    result = lax.reduce(a, _reduction_init_val(a, init_val), op, dims)
    if keepdims:
        shape_with_singletons = lax.subvals(shape(a), zip(dims, (1,) * len(dims)))
        result = lax.reshape(result, shape_with_singletons)
    if dtype and onp.dtype(dtype) != onp.dtype(result_dtype):
        result = lax.convert_element_type(result, dtype)
    return result


# Traceback (TypeError)
import jax.numpy as np
from jax import vmap
vmap(np.any)(np.array([[True, False], [False, False]]))
jax/lib/xla_bridge.py:138: UserWarning: No GPU found, falling back to CPU.
warnings.warn('No GPU found, falling back to CPU.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "jax/api.py", line 149, in batched_fun
out_flat = batching.batch(flat_fun, in_flat, in_axes_, out_axes)
File "jax/interpreters/batching.py", line 43, in batch
out_val, out_dim = batch_transform(fun).call_wrapped(in_vals, in_dims)
File "jax/linear_util.py", line 85, in call_wrapped
ans = self.f(*args, **self.kwargs)
File "jax/numpy/lax_numpy.py", line 607, in reduction
result = lax.reduce(a, _reduction_init_val(a, init_val), op, dims)
File "jax/lax.py", line 260, in reduce
dimensions=tuple(dimensions))
File "jax/core.py", line 74, in bind
out_tracer = top_trace.process_primitive(self, tracers, kwargs)
File "jax/interpreters/batching.py", line 119, in process_primitive
val_out, dim_out = batched_primitive(vals_in, dims_in, **params)
TypeError: reducer_batcher() takes exactly 4 arguments (3 given)

# Fixed code
def reduction(a, axis=None, dtype=None, out=None, keepdims=False):
    if out is not None:
        raise ValueError("reduction does not support `out` argument.")

    a = a if isinstance(a, ndarray) else asarray(a)
    a = preproc(a) if preproc else a
    dims = _reduction_dims(a, axis)
    result_dtype = _dtype(np_fun(onp.ones((), dtype=dtype or _dtype(a))))
    if _dtype(a) != result_dtype:
        a = lax.convert_element_type(a, result_dtype)
    result = lax.reduce(a, _reduction_init_val(a, init_val), op, dims)
    if keepdims:
        shape_with_singletons = lax.subvals(shape(a), zip(dims, (1,) * len(dims)))
        result = lax.reshape(result, shape_with_singletons)
    if dtype and onp.dtype(dtype) != onp.dtype(result_dtype):
        result = lax.convert_element_type(result, dtype)
    return result
# Buggy code
def clean(fields):
    visitor.visit_fields(fields, fieldset_func=schema_cleanup, field_func=field_cleanup)


# Traceback (ValueError)
$ python scripts/generator.py --ref v1.5.0
Loading schemas from git ref v1.5.0
Running generator. ECS version 1.5.0
Traceback (most recent call last):
File "scripts/generator.py", line 94, in <module>
main()
File "scripts/generator.py", line 44, in main
cleaner.clean(fields)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 23, in clean
visitor.visit_fields(fields, fieldset_func=schema_cleanup, field_func=field_cleanup)
File "<redacted>/ecs/scripts/schema/visitor.py", line 21, in visit_fields
visit_fields(details['fields'],
File "<redacted>/ecs/scripts/schema/visitor.py", line 19, in visit_fields
field_func(details)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 125, in field_cleanup
field_assertions_and_warnings(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 168, in field_assertions_and_warnings
single_line_short_description(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 189, in single_line_short_description
raise ValueError(msg)
ValueError: Short descriptions must be single line, and under 120 characters (current length: 134).
Offending field or field set: number
Short description:
Unique number allocated to the autonomous system. The autonomous system number (ASN) uniquely identifies each network on the Internet.

# Fixed code
def clean(fields, strict=False):
    global strict_mode
    strict_mode = strict
    visitor.visit_fields(fields, fieldset_func=schema_cleanup, field_func=field_cleanup)
# Buggy code
def schema_assertions_and_warnings(schema):
    """Additional checks on a fleshed out schema"""
    single_line_short_description(schema)


# Traceback (ValueError)
$ python scripts/generator.py --ref v1.5.0
Loading schemas from git ref v1.5.0
Running generator. ECS version 1.5.0
Traceback (most recent call last):
File "scripts/generator.py", line 94, in <module>
main()
File "scripts/generator.py", line 44, in main
cleaner.clean(fields)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 23, in clean
visitor.visit_fields(fields, fieldset_func=schema_cleanup, field_func=field_cleanup)
File "<redacted>/ecs/scripts/schema/visitor.py", line 21, in visit_fields
visit_fields(details['fields'],
File "<redacted>/ecs/scripts/schema/visitor.py", line 19, in visit_fields
field_func(details)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 125, in field_cleanup
field_assertions_and_warnings(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 168, in field_assertions_and_warnings
single_line_short_description(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 189, in single_line_short_description
raise ValueError(msg)
ValueError: Short descriptions must be single line, and under 120 characters (current length: 134).
Offending field or field set: number
Short description:
Unique number allocated to the autonomous system. The autonomous system number (ASN) uniquely identifies each network on the Internet.

# Fixed code
def schema_assertions_and_warnings(schema):
    """Additional checks on a fleshed out schema"""
    single_line_short_description(schema, strict=strict_mode)
# Buggy code
def field_assertions_and_warnings(field):
    """Additional checks on a fleshed out field"""
    if not ecs_helpers.is_intermediate(field):
        single_line_short_description(field)
        if field["field_details"]["level"] not in ACCEPTABLE_FIELD_LEVELS:
            msg = "Invalid level for field '{}'.\nValue: {}\nAcceptable values: {}".format(
                field["field_details"]["name"],
                field["field_details"]["level"],
                ACCEPTABLE_FIELD_LEVELS,
            )
            raise ValueError(msg)


# Traceback (ValueError)
$ python scripts/generator.py --ref v1.5.0
Loading schemas from git ref v1.5.0
Running generator. ECS version 1.5.0
Traceback (most recent call last):
File "scripts/generator.py", line 94, in <module>
main()
File "scripts/generator.py", line 44, in main
cleaner.clean(fields)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 23, in clean
visitor.visit_fields(fields, fieldset_func=schema_cleanup, field_func=field_cleanup)
File "<redacted>/ecs/scripts/schema/visitor.py", line 21, in visit_fields
visit_fields(details['fields'],
File "<redacted>/ecs/scripts/schema/visitor.py", line 19, in visit_fields
field_func(details)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 125, in field_cleanup
field_assertions_and_warnings(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 168, in field_assertions_and_warnings
single_line_short_description(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 189, in single_line_short_description
raise ValueError(msg)
ValueError: Short descriptions must be single line, and under 120 characters (current length: 134).
Offending field or field set: number
Short description:
Unique number allocated to the autonomous system. The autonomous system number (ASN) uniquely identifies each network on the Internet.

# Fixed code
def field_assertions_and_warnings(field):
    """Additional checks on a fleshed out field"""
    if not ecs_helpers.is_intermediate(field):
        # check short description length if in strict mode
        single_line_short_description(field, strict=strict_mode)
        if field["field_details"]["level"] not in ACCEPTABLE_FIELD_LEVELS:
            msg = "Invalid level for field '{}'.\nValue: {}\nAcceptable values: {}".format(
                field["field_details"]["name"],
                field["field_details"]["level"],
                ACCEPTABLE_FIELD_LEVELS,
            )
            raise ValueError(msg)
# Buggy code
def single_line_short_description(schema_or_field):
    short_length = len(schema_or_field["field_details"]["short"])
    if "\n" in schema_or_field["field_details"]["short"] or short_length > SHORT_LIMIT:
        msg = "Short descriptions must be single line, and under {} characters (current length: {}).\n".format(
            SHORT_LIMIT, short_length
        )
        msg += "Offending field or field set: {}\nShort description:\n  {}".format(
            schema_or_field["field_details"]["name"],
            schema_or_field["field_details"]["short"],
        )
        raise ValueError(msg)


# Traceback (ValueError)
$ python scripts/generator.py --ref v1.5.0
Loading schemas from git ref v1.5.0
Running generator. ECS version 1.5.0
Traceback (most recent call last):
File "scripts/generator.py", line 94, in <module>
main()
File "scripts/generator.py", line 44, in main
cleaner.clean(fields)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 23, in clean
visitor.visit_fields(fields, fieldset_func=schema_cleanup, field_func=field_cleanup)
File "<redacted>/ecs/scripts/schema/visitor.py", line 21, in visit_fields
visit_fields(details['fields'],
File "<redacted>/ecs/scripts/schema/visitor.py", line 19, in visit_fields
field_func(details)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 125, in field_cleanup
field_assertions_and_warnings(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 168, in field_assertions_and_warnings
single_line_short_description(field)
File "<redacted>/ecs/scripts/schema/cleaner.py", line 189, in single_line_short_description
raise ValueError(msg)
ValueError: Short descriptions must be single line, and under 120 characters (current length: 134).
Offending field or field set: number
Short description:
Unique number allocated to the autonomous system. The autonomous system number (ASN) uniquely identifies each network on the Internet.

# Fixed code
def single_line_short_description(schema_or_field, strict=True):
    short_length = len(schema_or_field["field_details"]["short"])
    if "\n" in schema_or_field["field_details"]["short"] or short_length > SHORT_LIMIT:
        msg = "Short descriptions must be single line, and under {} characters (current length: {}).\n".format(
            SHORT_LIMIT, short_length
        )
        msg += "Offending field or field set: {}\nShort description:\n  {}".format(
            schema_or_field["field_details"]["name"],
            schema_or_field["field_details"]["short"],
        )
        if strict:
            raise ValueError(msg)
        else:
            ecs_helpers.strict_warning(msg)
# Buggy code
def __repr__(self):
    info = {}
    if self._model_meta is not None:
        if self._model_meta.run_id is not None:
            info["run_id"] = self._model_meta.run_id
        if self._model_meta.artifact_path is not None:
            info["artifact_path"] = self._model_meta.artifact_path
        info["flavor"] = self._model_meta.flavors[FLAVOR_NAME]["loader_module"]
    return yaml.safe_dump(
        {"mlflow.pyfunc.loaded_model": info}, default_flow_style=False
    )


# Traceback (AttributeError)
from sklearn import datasets
from sklearn.model_selection import train_test_split
import mlflow
import xgboost as xgb
iris = datasets.load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

dtrain = xgb.DMatrix(X_train, label=y_train)
dtest = xgb.DMatrix(X_test, label=y_test)
params = {
"objective": "multi:softprob",
"num_class": 3,
"learning_rate": 0.3,
"eval_metric": "mlogloss",
"seed": 42
}
model = xgb.train(params, dtrain, evals=[(dtrain, "train")])
[0]     train-mlogloss:0.74723
[1]     train-mlogloss:0.54060
[2]     train-mlogloss:0.40276
[3]     train-mlogloss:0.30789
[4]     train-mlogloss:0.24052
[5]     train-mlogloss:0.19087
[6]     train-mlogloss:0.15471
[7]     train-mlogloss:0.12807
[8]     train-mlogloss:0.10722
[9]     train-mlogloss:0.09053

mlflow.xgboost.save_model(model, 'model')
model2 = mlflow.xgboost.load_model('model')
model2
<xgboost.core.Booster object at 0x7f9e1798d0f0>

model3 = mlflow.pyfunc.load_model('model')
model3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/lorenz/opt/miniconda3/envs/mlflow-1.11.0/lib/python3.6/site-packages/mlflow/pyfunc/__init__.py", line 437, in __repr__
if self._model_meta.run_id is not None:
AttributeError: 'Model' object has no attribute 'run_id'

# Fixed code
def __repr__(self):
    info = {}
    if self._model_meta is not None:
        if hasattr(self._model_meta, "run_id") and self._model_meta.run_id is not None:
            info["run_id"] = self._model_meta.run_id
        if (
            hasattr(self._model_meta, "artifact_path")
            and self._model_meta.artifact_path is not None
        ):
            info["artifact_path"] = self._model_meta.artifact_path
        info["flavor"] = self._model_meta.flavors[FLAVOR_NAME]["loader_module"]
    return yaml.safe_dump(
        {"mlflow.pyfunc.loaded_model": info}, default_flow_style=False
    )
# Buggy code
def list_artifacts(self, path=None):
    with self.get_ftp_client() as ftp:
        artifact_dir = self.path
        list_dir = posixpath.join(artifact_dir, path) if path else artifact_dir
        if not self._is_dir(ftp, list_dir):
            return []
        artifact_files = ftp.nlst(list_dir)
        artifact_files = list(filter(lambda x: x != "." and x != "..", artifact_files))
        infos = []
        for file_name in artifact_files:
            file_path = file_name if path is None else posixpath.join(path, file_name)
            full_file_path = posixpath.join(list_dir, file_name)
            if self._is_dir(ftp, full_file_path):
                infos.append(FileInfo(file_path, True, None))
            else:
                size = self._size(ftp, full_file_path)
                infos.append(FileInfo(file_path, False, size))
    return infos


# Traceback (mlflow.exceptions.MlflowException)
Traceback (most recent call last):
File "/Users/shaneing/PycharmProjects/gswatch/examples/load_model_from_ftp.py", line 9, in <module>
model = torch_load_model('ftp://mlflow:mlflow@10.10.10.1/mlruns/8/6f11ca34312a44df88f6b86f2f224f66/artifacts/fake-model/model')
└ <function load_model at 0x12e375710>
File "/usr/local/anaconda3/envs/gswatch3.7/lib/python3.7/site-packages/mlflow/pytorch/__init__.py", line 407, in load_model
pytorch_conf = _get_flavor_configuration(model_path=local_model_path, flavor_name=FLAVOR_NAME)
│                                    │                             └ 'pytorch'
│                                    └ '/var/folders/px/ncc8244n0sj6zsh5s6k8v7g40000gn/T/tmpo81ye7y5/model'
└ <function _get_flavor_configuration at 0x12e36d7a0>
File "/usr/local/anaconda3/envs/gswatch3.7/lib/python3.7/site-packages/mlflow/utils/model_utils.py", line 26, in _get_flavor_configuration
RESOURCE_DOES_NOT_EXIST)
mlflow.exceptions.MlflowException: Could not find an "MLmodel" configuration file at "/var/folders/px/ncc8244n0sj6zsh5s6k8v7g40000gn/T/tmpo81ye7y5/model"

# Fixed code
def list_artifacts(self, path=None):
    with self.get_ftp_client() as ftp:
        artifact_dir = self.path
        list_dir = posixpath.join(artifact_dir, path) if path else artifact_dir
        if not self._is_dir(ftp, list_dir):
            return []
        artifact_files = ftp.nlst(list_dir)
        artifact_files = list(filter(lambda x: x != "." and x != "..", artifact_files))
        # Make sure artifact_files is a list of file names because ftp.nlst
        # may return absolute paths.
        artifact_files = [os.path.basename(f) for f in artifact_files]
        infos = []
        for file_name in artifact_files:
            file_path = file_name if path is None else posixpath.join(path, file_name)
            full_file_path = posixpath.join(list_dir, file_name)
            if self._is_dir(ftp, full_file_path):
                infos.append(FileInfo(file_path, True, None))
            else:
                size = self._size(ftp, full_file_path)
                infos.append(FileInfo(file_path, False, size))
    return infos
# Buggy code
def log_artifacts(self, local_dir, artifact_path=None):
    dest_path = posixpath.join(self.path, artifact_path) if artifact_path else self.path

    dest_path = posixpath.join(dest_path, os.path.split(local_dir)[1])
    dest_path_re = os.path.split(local_dir)[1]
    if artifact_path:
        dest_path_re = posixpath.join(artifact_path, os.path.split(local_dir)[1])

    local_dir = os.path.abspath(local_dir)
    for root, _, filenames in os.walk(local_dir):
        upload_path = dest_path
        if root != local_dir:
            rel_path = os.path.relpath(root, local_dir)
            rel_path = relative_path_to_artifact_path(rel_path)
            upload_path = posixpath.join(dest_path_re, rel_path)
        if not filenames:
            with self.get_ftp_client() as ftp:
                self._mkdir(ftp, posixpath.join(self.path, upload_path))
        for f in filenames:
            if os.path.isfile(os.path.join(root, f)):
                self.log_artifact(os.path.join(root, f), upload_path)


# Traceback (mlflow.exceptions.MlflowException)
load_model("models:/MyKerasModel/3")

Traceback (most recent call last):
File "mini.py", line 6, in <module>
load_model("models:/MyKerasModel/3")
File "/Users/daniel.dercks/opt/anaconda3/envs/berner_macos_nogpu/lib/python3.7/site-packages/mlflow/keras.py", line 391, in load_model
flavor_conf = _get_flavor_configuration(model_path=local_model_path, flavor_name=FLAVOR_NAME)
File "/Users/daniel.dercks/opt/anaconda3/envs/berner_macos_nogpu/lib/python3.7/site-packages/mlflow/utils/model_utils.py", line 26, in _get_flavor_configuration
RESOURCE_DOES_NOT_EXIST)
mlflow.exceptions.MlflowException: Could not find an "MLmodel" configuration file at "/var/folders/jx/02yypg8x5wjdhhr54xcmzhy87m0bvt/T/tmpmo0g0x22/"

# Fixed code
def log_artifacts(self, local_dir, artifact_path=None):
    dest_path = posixpath.join(self.path, artifact_path) if artifact_path else self.path

    local_dir = os.path.abspath(local_dir)
    for root, _, filenames in os.walk(local_dir):
        upload_path = dest_path
        if root != local_dir:
            rel_path = os.path.relpath(root, local_dir)
            upload_path = relative_path_to_artifact_path(rel_path)
        if not filenames:
            with self.get_ftp_client() as ftp:
                self._mkdir(ftp, posixpath.join(self.path, upload_path))
        for f in filenames:
            if os.path.isfile(os.path.join(root, f)):
                self.log_artifact(os.path.join(root, f), upload_path)
# Buggy code
def _get_rest_store(store_uri, **_):
    def get_default_host_creds():
        return rest_utils.MlflowHostCreds(
            host=store_uri,
            username=os.environ.get(_TRACKING_USERNAME_ENV_VAR),
            password=os.environ.get(_TRACKING_PASSWORD_ENV_VAR),
            token=os.environ.get(_TRACKING_TOKEN_ENV_VAR),
            ignore_tls_verification=os.environ.get(_TRACKING_INSECURE_TLS_ENV_VAR)
            == "true",
            client_cert_path=os.environ.get(_TRACKING_CLIENT_CERT_PATH_ENV_VAR),
            server_cert_path=os.environ.get(_TRACKING_SERVER_CERT_PATH_ENV_VAR),
        )

    return RestStore(get_default_host_creds)


# Traceback (AttributeError)
python mlflow_pickle_error.py
Traceback (most recent call last):
File "mlflow_test.py", line 14, in <module>
pickle.dump(cls, open('test_dump.pkl', 'wb'))
AttributeError: Can't pickle local object '_get_rest_store.<locals>.get_default_host_creds'

# Fixed code
def _get_rest_store(store_uri, **_):
    return RestStore(partial(_get_default_host_creds, store_uri))
# Buggy code
def _call_endpoint(self, service, api, json_body):
    endpoint, method = _SERVICE_AND_METHOD_TO_INFO[service][api]
    response_proto = api.Response()
    return call_endpoint(
        get_databricks_host_creds(), endpoint, method, json_body, response_proto
    )


# Traceback (AttributeError)
python mlflow_pickle_error.py
Traceback (most recent call last):
File "mlflow_test.py", line 14, in <module>
pickle.dump(cls, open('test_dump.pkl', 'wb'))
AttributeError: Can't pickle local object '_get_rest_store.<locals>.get_default_host_creds'

# Fixed code
def _call_endpoint(self, service, api, json_body):
    db_profile = get_db_profile_from_uri(mlflow.tracking.get_tracking_uri())
    db_creds = get_databricks_host_creds(db_profile)
    endpoint, method = _SERVICE_AND_METHOD_TO_INFO[service][api]
    response_proto = api.Response()
    return call_endpoint(db_creds, endpoint, method, json_body, response_proto)
# Buggy code
def to_pandas(self) -> Union[np.dtype, PandasExtensionDtype]:
    """Get equivalent pandas data type."""
    return self._pandas_type


# Traceback (AttributeError)
python mlflow_pickle_error.py
Traceback (most recent call last):
File "mlflow_test.py", line 14, in <module>
pickle.dump(cls, open('test_dump.pkl', 'wb'))
AttributeError: Can't pickle local object '_get_rest_store.<locals>.get_default_host_creds'

# Fixed code
def to_pandas(self) -> np.dtype:
    """Get equivalent pandas data type."""
    return self._pandas_type
# Buggy code
def check(self, instance):
    config = self.get_config(instance)
    if config is None:
        return

    tags = list(config["tags"])

    # We access the version of the Vault API corresponding to each instance's `api_url`.
    try:
        config["api"]["check_leader"](config, tags)
        config["api"]["check_health"](config, tags)
    except ApiUnreachable:
        return

    self.service_check(self.SERVICE_CHECK_CONNECT, AgentCheck.OK, tags=tags)


# Traceback (TypeError)
Error: string indices must be integers, not str
Traceback (most recent call last):
File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/base/checks/base.py", line 366, in run
self.check(copy.deepcopy(self.instances[0]))
File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/vault/vault.py", line 38, in check
config = self.get_config(instance)
File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/vault/vault.py", line 118, in get_config
config['api'] = self.api_versions.get(api_version, self.DEFAULT_API_VERSION)['functions']
TypeError: string indices must be integers, not str

# Fixed code
def check(self, instance):
    config = self.get_config(instance)
    if config is None:
        return

    api = config["api"]
    tags = list(config["tags"])

    # We access the version of the Vault API corresponding to each instance's `api_url`.
    try:
        api["check_leader"](config, tags)
        api["check_health"](config, tags)
    except ApiUnreachable:
        return

    self.service_check(self.SERVICE_CHECK_CONNECT, AgentCheck.OK, tags=tags)
# Buggy code
def options(self, request, *args, **kwargs):
    r = Response.text("ok")
    if self.ds.cors:
        r.headers["Access-Control-Allow-Origin"] = "*"
    return r


# Traceback (TypeError)
Traceback (most recent call last):
File "[path-to-python]/site-packages/datasette/app.py", line 1033, in route_path
response = await view(request, send)
File "[path-to-python]/site-packages/datasette/views/base.py", line 146, in view
request, **request.scope["url_route"]["kwargs"]
File "[path-to-python]/site-packages/datasette/views/base.py", line 118, in dispatch_request
return await handler(request, *args, **kwargs)
TypeError: object Response can't be used in 'await' expression

# Fixed code
async def options(self, request, *args, **kwargs):
    r = Response.text("ok")
    if self.ds.cors:
        r.headers["Access-Control-Allow-Origin"] = "*"
    return r
# Buggy code
def link_or_copy_directory(src, dst):
    try:
        shutil.copytree(src, dst, copy_function=os.link, dirs_exist_ok=True)
    except OSError:
        shutil.copytree(src, dst, dirs_exist_ok=True)


# Traceback (shutil.Error)
Traceback (most recent call last):
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/utils/__init__.py", line 607, in link_or_copy_directory
shutil.copytree(src, dst, copy_function=os.link)
File "/usr/lib/python3.7/shutil.py", line 365, in copytree
raise Error(errors)
shutil.Error: [('/myfolder/youtubeComunePalermo/processing/./template/base.html', '/tmp/tmps9_4mzc4/templates/base.html', "[Errno 18] Invalid cross-device link: '/myfolder/youtubeComunePalermo/processing/./template/base.html' -> '/tmp/tmps9_4mzc4/templates/base.html'"), ('/myfolder/youtubeComunePalermo/processing/./template/index.html', '/tmp/tmps9_4mzc4/templates/index.html', "[Errno 18] Invalid cross-device link: '/myfolder/youtubeComunePalermo/processing/./template/index.html' -> '/tmp/tmps9_4mzc4/templates/index.html'")]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/aborruso/.local/bin/datasette", line 8, in <module>
sys.exit(cli())
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/publish/heroku.py", line 103, in heroku
extra_metadata,
File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/publish/heroku.py", line 191, in temporary_heroku_directory
os.path.join(tmp.name, "templates"),
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/utils/__init__.py", line 609, in link_or_copy_directory
shutil.copytree(src, dst)
File "/usr/lib/python3.7/shutil.py", line 321, in copytree
os.makedirs(dst)
File "/usr/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/tmp/tmps9_4mzc4/templates'

# Fixed code
def link_or_copy_directory(src, dst):
    try:
        copytree(src, dst, copy_function=os.link, dirs_exist_ok=True)
    except OSError:
        copytree(src, dst, dirs_exist_ok=True)
# Buggy code
def link_or_copy_directory(src, dst):
    try:
        shutil.copytree(src, dst, copy_function=os.link)
    except OSError:
        shutil.copytree(src, dst)


# Traceback (shutil.Error)
Traceback (most recent call last):
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/utils/__init__.py", line 607, in link_or_copy_directory
shutil.copytree(src, dst, copy_function=os.link)
File "/usr/lib/python3.7/shutil.py", line 365, in copytree
raise Error(errors)
shutil.Error: [('/myfolder/youtubeComunePalermo/processing/./template/base.html', '/tmp/tmps9_4mzc4/templates/base.html', "[Errno 18] Invalid cross-device link: '/myfolder/youtubeComunePalermo/processing/./template/base.html' -> '/tmp/tmps9_4mzc4/templates/base.html'"), ('/myfolder/youtubeComunePalermo/processing/./template/index.html', '/tmp/tmps9_4mzc4/templates/index.html', "[Errno 18] Invalid cross-device link: '/myfolder/youtubeComunePalermo/processing/./template/index.html' -> '/tmp/tmps9_4mzc4/templates/index.html'")]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/aborruso/.local/bin/datasette", line 8, in <module>
sys.exit(cli())
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/aborruso/.local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/publish/heroku.py", line 103, in heroku
extra_metadata,
File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/publish/heroku.py", line 191, in temporary_heroku_directory
os.path.join(tmp.name, "templates"),
File "/home/aborruso/.local/lib/python3.7/site-packages/datasette/utils/__init__.py", line 609, in link_or_copy_directory
shutil.copytree(src, dst)
File "/usr/lib/python3.7/shutil.py", line 321, in copytree
os.makedirs(dst)
File "/usr/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/tmp/tmps9_4mzc4/templates'

# Fixed code
def link_or_copy_directory(src, dst):
    try:
        shutil.copytree(src, dst, copy_function=os.link, dirs_exist_ok=True)
    except OSError:
        shutil.copytree(src, dst, dirs_exist_ok=True)
# Buggy code
def path(self):
    return (self.scope.get("raw_path", self.scope["path"].encode("latin-1"))).decode(
        "latin-1"
    )


# Traceback (UnicodeEncodeError)
Traceback (most recent call last):
File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/asgi.py", line 100, in __call__
return await view(new_scope, receive, send)
File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/asgi.py", line 172, in view
request, **scope["url_route"]["kwargs"]
File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/views/base.py", line 267, in get
request, database, hash, correct_hash_provided, **kwargs
File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/views/base.py", line 471, in view_get
for key in self.ds.renderers.keys()
File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/views/base.py", line 471, in <dictcomp>
for key in self.ds.renderers.keys()
File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/__init__.py", line 655, in path_with_format
path = request.path
File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/asgi.py", line 49, in path
self.scope.get("raw_path", self.scope["path"].encode("latin-1"))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 9-11: ordinal not in range(256)

# Fixed code
def path(self):
    if "raw_path" in self.scope:
        return self.scope["raw_path"].decode("latin-1")
    else:
        return self.scope["path"].decode("utf-8")
# Buggy code
def prepare_dataset_for_training(nlp_dataset):
    """Changes an `nlp` dataset into the proper format for tokenization."""

    def prepare_example_dict(ex):
        """Returns the values in order corresponding to the data.

        ex:
            'Some text input'
        or in the case of multi-sequence inputs:
            ('The premise', 'the hypothesis',)
        etc.
        """
        values = list(ex.values())
        if len(values) == 1:
            return values[0]
        return values

    return zip(*((prepare_example_dict(x[0]), x[1]) for x in nlp_dataset))


# Traceback (ValueError)
$ textattack train --model distilbert-base-uncased --dataset glue:wnli --batch-size 128 --epochs 5 --max-length 256 --learning-rate 3e-05

...

Traceback (most recent call last):
File "/u/jm8wx/.conda/envs/torch/bin/textattack", line 33, in <module>
sys.exit(load_entry_point('textattack', 'console_scripts', 'textattack')())
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/textattack_cli.py", line 41, in main
args.func.run(args)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/train_model_command.py", line 30, in run
train_model(args)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/run_training.py", line 108, in train_model
train_text_ids = batch_encode(tokenizer, train_text)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/run_training.py", line 28, in batch_encode
return tokenizer.batch_encode(text_list)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/models/tokenizers/auto_tokenizer.py", line 57, in batch_encode
encodings = self.tokenizer.batch_encode_plus(
File "/u/jm8wx/.conda/envs/torch/lib/python3.8/site-packages/transformers/tokenization_utils.py", line 2451, in batch_encode_plus
raise ValueError(
ValueError: batch_text_or_text_pairs has to be a list (got <class 'tuple'>)
textattack train --model distilbert-base-uncased --dataset glue:wnli --batch-size 64 --epochs 5 --max-length 256 --learning-rate 5e-05

# Fixed code
def prepare_dataset_for_training(nlp_dataset):
    """Changes an `nlp` dataset into the proper format for tokenization."""

    def prepare_example_dict(ex):
        """Returns the values in order corresponding to the data.

        ex:
            'Some text input'
        or in the case of multi-sequence inputs:
            ('The premise', 'the hypothesis',)
        etc.
        """
        values = list(ex.values())
        if len(values) == 1:
            return values[0]
        return tuple(values)

    text, outputs = zip(*((prepare_example_dict(x[0]), x[1]) for x in nlp_dataset))
    return list(text), list(outputs)
# Buggy code
def prepare_example_dict(ex):
    """Returns the values in order corresponding to the data.

    ex:
        'Some text input'
    or in the case of multi-sequence inputs:
        ('The premise', 'the hypothesis',)
    etc.
    """
    values = list(ex.values())
    if len(values) == 1:
        return values[0]
    return values


# Traceback (ValueError)
$ textattack train --model distilbert-base-uncased --dataset glue:wnli --batch-size 128 --epochs 5 --max-length 256 --learning-rate 3e-05

...

Traceback (most recent call last):
File "/u/jm8wx/.conda/envs/torch/bin/textattack", line 33, in <module>
sys.exit(load_entry_point('textattack', 'console_scripts', 'textattack')())
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/textattack_cli.py", line 41, in main
args.func.run(args)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/train_model_command.py", line 30, in run
train_model(args)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/run_training.py", line 108, in train_model
train_text_ids = batch_encode(tokenizer, train_text)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/run_training.py", line 28, in batch_encode
return tokenizer.batch_encode(text_list)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/models/tokenizers/auto_tokenizer.py", line 57, in batch_encode
encodings = self.tokenizer.batch_encode_plus(
File "/u/jm8wx/.conda/envs/torch/lib/python3.8/site-packages/transformers/tokenization_utils.py", line 2451, in batch_encode_plus
raise ValueError(
ValueError: batch_text_or_text_pairs has to be a list (got <class 'tuple'>)
textattack train --model distilbert-base-uncased --dataset glue:wnli --batch-size 64 --epochs 5 --max-length 256 --learning-rate 5e-05

# Fixed code
def prepare_example_dict(ex):
    """Returns the values in order corresponding to the data.

    ex:
        'Some text input'
    or in the case of multi-sequence inputs:
        ('The premise', 'the hypothesis',)
    etc.
    """
    values = list(ex.values())
    if len(values) == 1:
        return values[0]
    return tuple(values)
# Buggy code
def __init__(
    self, word_id_map={}, pad_token_id=None, unk_token_id=None, max_length=256
):
    super().__init__(
        word_id_map=word_id_map,
        unk_token_id=unk_token_id,
        pad_token_id=pad_token_id,
        lowercase=True,
    )
    self.pad_id = pad_token_id
    self.oov_id = unk_token_id
    self.convert_id_to_word = self.id_to_token
    # Set defaults.
    self.enable_padding(max_length=max_length, pad_id=pad_token_id)
    self.enable_truncation(max_length=max_length)


# Traceback (ValueError)
$ textattack train --model distilbert-base-uncased --dataset glue:wnli --batch-size 128 --epochs 5 --max-length 256 --learning-rate 3e-05

...

Traceback (most recent call last):
File "/u/jm8wx/.conda/envs/torch/bin/textattack", line 33, in <module>
sys.exit(load_entry_point('textattack', 'console_scripts', 'textattack')())
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/textattack_cli.py", line 41, in main
args.func.run(args)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/train_model_command.py", line 30, in run
train_model(args)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/run_training.py", line 108, in train_model
train_text_ids = batch_encode(tokenizer, train_text)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/commands/train_model/run_training.py", line 28, in batch_encode
return tokenizer.batch_encode(text_list)
File "/p/qdata/jm8wx/research/text_attacks/textattack/textattack/models/tokenizers/auto_tokenizer.py", line 57, in batch_encode
encodings = self.tokenizer.batch_encode_plus(
File "/u/jm8wx/.conda/envs/torch/lib/python3.8/site-packages/transformers/tokenization_utils.py", line 2451, in batch_encode_plus
raise ValueError(
ValueError: batch_text_or_text_pairs has to be a list (got <class 'tuple'>)
textattack train --model distilbert-base-uncased --dataset glue:wnli --batch-size 64 --epochs 5 --max-length 256 --learning-rate 5e-05

# Fixed code
def __init__(
    self, word_id_map={}, pad_token_id=None, unk_token_id=None, max_length=256
):
    super().__init__(
        word_id_map=word_id_map,
        unk_token_id=unk_token_id,
        pad_token_id=pad_token_id,
        lowercase=True,
    )
    self.pad_id = pad_token_id
    self.oov_id = unk_token_id
    self.convert_id_to_word = self.id_to_token
    # Set defaults.
    self.enable_padding(length=max_length, pad_id=pad_token_id)
    self.enable_truncation(max_length=max_length)
# Buggy code
def _validate_natural(value):
    if value < 0:
        raise exceptions.ApiError("Must be a natural number", status_code=422)


# Traceback (psycopg2.error)
2020-07-20T10:41:24.80-0400 [APP/PROC/WEB/4] ERR [2020-07-20 14:41:24 +0000] [301] [ERROR] Error handling request /v1/candidates/?sort_nulls_last=false&amp;sort_hide_null=false&amp;office=P&amp;per_page=100&amp;sort_null_only=false&amp;sort=name&amp;page=0&amp;election_year=2024
2020-07-20T10:41:24.80-0400 [APP/PROC/WEB/4] ERR Traceback (most recent call last):
2020-07-20T10:41:24.80-0400 [APP/PROC/WEB/4] ERR   File "/home/vcap/deps/0/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1244, in _execute_context
2020-07-20T10:41:24.80-0400 [APP/PROC/WEB/4] ERR     cursor, statement, parameters, context
2020-07-20T10:41:24.80-0400 [APP/PROC/WEB/4] ERR   File "/home/vcap/deps/0/python/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
2020-07-20T10:41:24.80-0400 [APP/PROC/WEB/4] ERR     cursor.execute(statement, parameters)
2020-07-20T10:41:24.80-0400 [APP/PROC/WEB/4] ERR psycopg2.errors.InvalidRowCountInResultOffsetClause: OFFSET must not be negative

# Fixed code
def _validate_natural(value):
    if value <= 0:
        raise exceptions.ApiError("Must be greater than zero", status_code=422)
# Buggy code
def run(self):
    main_thread = _get_main_thread()
    while main_thread.is_alive():
        doLock = threading.Lock()
        doLock.acquire()
        if self.current != self.last:
            doLock.release()
            if self.queue[self.current]["taskType"] == TASK_EMAIL:
                self._send_raw_email()
            if self.queue[self.current]["taskType"] == TASK_CONVERT:
                self._convert_any_format()
            if self.queue[self.current]["taskType"] == TASK_CONVERT_ANY:
                self._convert_any_format()
            # TASK_UPLOAD is handled implicitly
            self.current += 1
        else:
            doLock.release()
        if main_thread.is_alive():
            time.sleep(1)


# Traceback (IndexError)
Traceback (most recent call last):
File "calibre-web/vendor/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "calibre-web/vendor/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "calibre-web/vendor/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "calibre-web/vendor/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "calibre-web/vendor/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "calibre-web/cps/web.py", line 348, in decorated_view
return func(*args, **kwargs)
File "calibre-web/cps/web.py", line 490, in inner
return f(*args, **kwargs)
File "calibre-web/cps/web.py", line 3868, in upload
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
File "calibre-web/cps/worker.py", line 406, in add_upload
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
IndexError: list index out of range

# Fixed code
def run(self):
    main_thread = _get_main_thread()
    while main_thread.is_alive():
        doLock = threading.Lock()
        doLock.acquire()
        if self.current != self.last:
            index = self.current
            doLock.release()
            if self.queue[index]["taskType"] == TASK_EMAIL:
                self._send_raw_email()
            if self.queue[index]["taskType"] == TASK_CONVERT:
                self._convert_any_format()
            if self.queue[index]["taskType"] == TASK_CONVERT_ANY:
                self._convert_any_format()
            # TASK_UPLOAD is handled implicitly
            doLock.acquire()
            self.current += 1
            doLock.release()
        else:
            doLock.release()
        if main_thread.is_alive():
            time.sleep(1)
# Buggy code
def get_taskstatus(self):
    if self.current < len(self.queue):
        if self.UIqueue[self.current]["stat"] == STAT_STARTED:
            if self.queue[self.current]["taskType"] == TASK_EMAIL:
                self.UIqueue[self.current]["progress"] = self.get_send_status()
            self.UIqueue[self.current]["formRuntime"] = (
                datetime.now() - self.queue[self.current]["starttime"]
            )
            self.UIqueue[self.current]["rt"] = (
                self.UIqueue[self.current]["formRuntime"].days * 24 * 60
                + self.UIqueue[self.current]["formRuntime"].seconds
                + self.UIqueue[self.current]["formRuntime"].microseconds
            )
    return self.UIqueue


# Traceback (IndexError)
Traceback (most recent call last):
File "calibre-web/vendor/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "calibre-web/vendor/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "calibre-web/vendor/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "calibre-web/vendor/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "calibre-web/vendor/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "calibre-web/cps/web.py", line 348, in decorated_view
return func(*args, **kwargs)
File "calibre-web/cps/web.py", line 490, in inner
return f(*args, **kwargs)
File "calibre-web/cps/web.py", line 3868, in upload
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
File "calibre-web/cps/worker.py", line 406, in add_upload
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
IndexError: list index out of range

# Fixed code
def get_taskstatus(self):
    doLock = threading.Lock()
    doLock.acquire()
    if self.current < len(self.queue):
        if self.UIqueue[self.current]["stat"] == STAT_STARTED:
            if self.queue[self.current]["taskType"] == TASK_EMAIL:
                self.UIqueue[self.current]["progress"] = self.get_send_status()
            self.UIqueue[self.current]["formRuntime"] = (
                datetime.now() - self.queue[self.current]["starttime"]
            )
            self.UIqueue[self.current]["rt"] = (
                self.UIqueue[self.current]["formRuntime"].days * 24 * 60
                + self.UIqueue[self.current]["formRuntime"].seconds
                + self.UIqueue[self.current]["formRuntime"].microseconds
            )
    doLock.release()
    return self.UIqueue
# Buggy code
def _convert_any_format(self):
    # convert book, and upload in case of google drive
    self.UIqueue[self.current]["stat"] = STAT_STARTED
    self.queue[self.current]["starttime"] = datetime.now()
    self.UIqueue[self.current]["formStarttime"] = self.queue[self.current]["starttime"]
    curr_task = self.queue[self.current]["taskType"]
    filename = self._convert_ebook_format()
    if filename:
        if config.config_use_google_drive:
            gdriveutils.updateGdriveCalibreFromLocal()
        if curr_task == TASK_CONVERT:
            self.add_email(
                self.queue[self.current]["settings"]["subject"],
                self.queue[self.current]["path"],
                filename,
                self.queue[self.current]["settings"],
                self.queue[self.current]["kindle"],
                self.UIqueue[self.current]["user"],
                self.queue[self.current]["title"],
                self.queue[self.current]["settings"]["body"],
            )


# Traceback (IndexError)
Traceback (most recent call last):
File "calibre-web/vendor/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "calibre-web/vendor/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "calibre-web/vendor/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "calibre-web/vendor/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "calibre-web/vendor/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "calibre-web/cps/web.py", line 348, in decorated_view
return func(*args, **kwargs)
File "calibre-web/cps/web.py", line 490, in inner
return f(*args, **kwargs)
File "calibre-web/cps/web.py", line 3868, in upload
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
File "calibre-web/cps/worker.py", line 406, in add_upload
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
IndexError: list index out of range

# Fixed code
def _convert_any_format(self):
    # convert book, and upload in case of google drive
    doLock = threading.Lock()
    doLock.acquire()
    index = self.current
    doLock.release()
    self.UIqueue[index]["stat"] = STAT_STARTED
    self.queue[index]["starttime"] = datetime.now()
    self.UIqueue[index]["formStarttime"] = self.queue[self.current]["starttime"]
    curr_task = self.queue[index]["taskType"]
    filename = self._convert_ebook_format()
    if filename:
        if config.config_use_google_drive:
            gdriveutils.updateGdriveCalibreFromLocal()
        if curr_task == TASK_CONVERT:
            self.add_email(
                self.queue[index]["settings"]["subject"],
                self.queue[index]["path"],
                filename,
                self.queue[index]["settings"],
                self.queue[index]["kindle"],
                self.UIqueue[index]["user"],
                self.queue[index]["title"],
                self.queue[index]["settings"]["body"],
            )