gurudesh/pytracebugs huggingface dataset:
# Buggy code
def iter_packaging_files(project):
    """Yield the filenames for all files in the project.

    The filenames are relative to "debugpy/_vendored".  This is most
    useful for the "package data" in a setup.py.
    """
    # TODO: Use default filters?  __pycache__ and .pyc?
    prune_dir = None
    exclude_file = None
    try:
        mod = import_module("._{}_packaging".format(project), __name__)
    except ImportError:
        pass
    else:
        prune_dir = getattr(mod, "prune_dir", prune_dir)
        exclude_file = getattr(mod, "exclude_file", exclude_file)
    results = iter_project_files(
        project,
        relative=True,
        prune_dir=prune_dir,
        exclude_file=exclude_file,
    )
    for _, _, filename in results:
        yield filename


# Traceback (AttributeError)
/usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
~/git-repo/odoo(master ✗)  /usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/__main__.py", line 43, in <module>
from debugpy.server import cli
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/server/__init__.py", line 9, in <module>
import debugpy._vendored.force_pydevd  # noqa
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/force_pydevd.py", line 15, in <module>
prefix_matcher('pydev', '_pydev'))
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/__init__.py", line 106, in check_modules
elif not mod.__file__.startswith(root):
AttributeError: 'NoneType' object has no attribute 'startswith'

# Fixed code
def iter_packaging_files(project):
    """Yield the filenames for all files in the project.

    The filenames are relative to "debugpy/_vendored".  This is most
    useful for the "package data" in a setup.py.
    """
    # TODO: Use default filters?  __pycache__ and .pyc?
    prune_dir = None
    exclude_file = None
    try:
        mod = import_module("._{}_packaging".format(project), __name__)
    except ImportError:
        pass
    else:
        prune_dir = getattr(mod, "prune_dir", prune_dir)
        exclude_file = getattr(mod, "exclude_file", exclude_file)
    results = iter_project_files(
        project, relative=True, prune_dir=prune_dir, exclude_file=exclude_file
    )
    for _, _, filename in results:
        yield filename
# Buggy code
def check_modules(project, match, root=None):
    """Verify that only vendored modules have been imported."""
    if root is None:
        root = project_root(project)
    extensions = []
    unvendored = {}
    for modname, mod in list(sys.modules.items()):
        if not match(modname, mod):
            continue
        if not hasattr(mod, "__file__"):  # extension module
            extensions.append(modname)
        elif not mod.__file__.startswith(root):
            unvendored[modname] = mod.__file__
    return unvendored, extensions


# Traceback (AttributeError)
/usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
~/git-repo/odoo(master ✗)  /usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/__main__.py", line 43, in <module>
from debugpy.server import cli
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/server/__init__.py", line 9, in <module>
import debugpy._vendored.force_pydevd  # noqa
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/force_pydevd.py", line 15, in <module>
prefix_matcher('pydev', '_pydev'))
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/__init__.py", line 106, in check_modules
elif not mod.__file__.startswith(root):
AttributeError: 'NoneType' object has no attribute 'startswith'

# Fixed code
def check_modules(project, match, root=None):
    """Verify that only vendored modules have been imported."""
    if root is None:
        root = project_root(project)
    extensions = []
    unvendored = {}
    for modname, mod in list(sys.modules.items()):
        if not match(modname, mod):
            continue
        try:
            filename = getattr(mod, "__file__", None)
        except:  # In theory it's possible that any error is raised when accessing __file__
            filename = None
        if not filename:  # extension module
            extensions.append(modname)
        elif not filename.startswith(root):
            unvendored[modname] = filename
    return unvendored, extensions
# Buggy code
def get_file(mod):
    f = None
    try:
        f = inspect.getsourcefile(mod) or inspect.getfile(mod)
    except:
        if hasattr_checked(mod, "__file__"):
            f = mod.__file__
            if f.lower(f[-4:]) in [".pyc", ".pyo"]:
                filename = f[:-4] + ".py"
                if os.path.exists(filename):
                    f = filename

    return f


# Traceback (AttributeError)
/usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
~/git-repo/odoo(master ✗)  /usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/__main__.py", line 43, in <module>
from debugpy.server import cli
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/server/__init__.py", line 9, in <module>
import debugpy._vendored.force_pydevd  # noqa
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/force_pydevd.py", line 15, in <module>
prefix_matcher('pydev', '_pydev'))
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/__init__.py", line 106, in check_modules
elif not mod.__file__.startswith(root):
AttributeError: 'NoneType' object has no attribute 'startswith'

# Fixed code
def get_file(mod):
    f = None
    try:
        f = inspect.getsourcefile(mod) or inspect.getfile(mod)
    except:
        try:
            f = getattr(mod, "__file__", None)
        except:
            f = None
        if f and f.lower(f[-4:]) in [".pyc", ".pyo"]:
            filename = f[:-4] + ".py"
            if os.path.exists(filename):
                f = filename

    return f
# Buggy code
def create_server(host, port, timeout=None):
    """Return a local server socket listening on the given port."""
    if host is None:
        host = "127.0.0.1"
    if port is None:
        port = 0

    try:
        server = _new_sock()
        server.bind((host, port))
        if timeout is not None:
            server.settimeout(timeout)
        server.listen(1)
    except Exception:
        server.close()
        raise
    return server


# Traceback (ConnectionRefusedError)
C:\Python37\python.exe c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\launcher C:\GIT\issues\issue9214/test_mp.py
Could not connect to 127.0.0.1: 50734
Traceback (most recent call last):
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 514, in start_client
s.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\pydevd.py", line 2550, in settrace
client_access_token,
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\pydevd.py", line 2610, in _locked_settrace
py_db.connect(host, port)  # Note: connect can raise error.
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\pydevd.py", line 1179, in connect
s = start_client(host, port)
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 514, in start_client
s.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Python37\lib\concurrent\futures\process.py", line 102, in _python_exit
thread_wakeup.wakeup()
File "C:\Python37\lib\concurrent\futures\process.py", line 90, in wakeup
self._writer.send_bytes(b"")
File "C:\Python37\lib\multiprocessing\connection.py", line 183, in send_bytes
self._check_closed()
File "C:\Python37\lib\multiprocessing\connection.py", line 136, in _check_closed
raise OSError("handle is closed")
OSError: handle is closed

# Fixed code
def create_server(host, port=0, backlog=socket.SOMAXCONN, timeout=None):
    """Return a local server socket listening on the given port."""
    if host is None:
        host = "127.0.0.1"
    if port is None:
        port = 0

    try:
        server = _new_sock()
        server.bind((host, port))
        if timeout is not None:
            server.settimeout(timeout)
        server.listen(backlog)
    except Exception:
        server.close()
        raise
    return server
# Buggy code
def accept_worker():
    while True:
        try:
            sock, (other_host, other_port) = cls.listener.accept()
        except OSError:
            # Listener socket has been closed.
            break

        log.info(
            "Accepted incoming {0} connection from {1}:{2}.",
            name,
            other_host,
            other_port,
        )
        cls(sock)


# Traceback (ConnectionRefusedError)
C:\Python37\python.exe c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\launcher C:\GIT\issues\issue9214/test_mp.py
Could not connect to 127.0.0.1: 50734
Traceback (most recent call last):
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 514, in start_client
s.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\pydevd.py", line 2550, in settrace
client_access_token,
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\pydevd.py", line 2610, in _locked_settrace
py_db.connect(host, port)  # Note: connect can raise error.
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\pydevd.py", line 1179, in connect
s = start_client(host, port)
File "c:\Users\kanadig\.vscode\extensions\ms-python.python-2020.2.60897-dev\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 514, in start_client
s.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Python37\lib\concurrent\futures\process.py", line 102, in _python_exit
thread_wakeup.wakeup()
File "C:\Python37\lib\concurrent\futures\process.py", line 90, in wakeup
self._writer.send_bytes(b"")
File "C:\Python37\lib\multiprocessing\connection.py", line 183, in send_bytes
self._check_closed()
File "C:\Python37\lib\multiprocessing\connection.py", line 136, in _check_closed
raise OSError("handle is closed")
OSError: handle is closed

# Fixed code
def accept_worker():
    while True:
        try:
            sock, (other_host, other_port) = listener.accept()
        except OSError:
            # Listener socket has been closed.
            break

        log.info(
            "Accepted incoming {0} connection from {1}:{2}.",
            name,
            other_host,
            other_port,
        )
        handler(sock)
# Buggy code
def get(self, name):
    try:
        if is_custom(name):
            model = ca.custom_models.get_model_data(name)
        else:
            model = ca.mindsdb_native.get_model_data(name)
    except Exception as e:
        abort(404, "")

    for k in ["train_end_at", "updated_at", "created_at"]:
        if k in model and model[k] is not None:
            model[k] = parse_datetime(model[k])

    return model


# Traceback (KeyError)
'typing'
ERROR while fetching data for query: SELECT `satisfaction`, `satisfaction_confidence` FROM `mindsdb`.`airline_data` WHERE ((`age` = 30))
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/classes/sql_query.py", line 68, in fetch
self._fetchData()
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/classes/sql_query.py", line 440, in _fetchData
came_from=self.integration
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py", line 220, in select
for f in model['data_analysis_v2']['columns']
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py", line 220, in <dictcomp>
for f in model['data_analysis_v2']['columns']
KeyError: 'typing'
'typing'

# Fixed code
def get(self, name):
    try:
        if is_custom(name):
            model = ca.custom_models.get_model_data(name)
        else:
            model = ca.mindsdb_native.get_model_data(name, native_view=True)
    except Exception as e:
        abort(404, "")

    for k in ["train_end_at", "updated_at", "created_at"]:
        if k in model and model[k] is not None:
            model[k] = parse_datetime(model[k])

    return model
# Buggy code
def get(self, name):
    """List of predictors colums"""
    try:
        if is_custom(name):
            model = ca.custom_models.get_model_data(name)
        else:
            model = ca.mindsdb_native.get_model_data(name)
    except Exception:
        abort(404, "Invalid predictor name")

    columns = []
    for array, is_target_array in [
        (model["data_analysis"]["target_columns_metadata"], True),
        (model["data_analysis"]["input_columns_metadata"], False),
    ]:
        for col_data in array:
            column = {
                "name": col_data["column_name"],
                "data_type": col_data["data_type"].lower(),
                "is_target_column": is_target_array,
            }
            if column["data_type"] == "categorical":
                column["distribution"] = col_data["data_distribution"][
                    "data_histogram"
                ]["x"]
            columns.append(column)

    return columns, 200


# Traceback (KeyError)
'typing'
ERROR while fetching data for query: SELECT `satisfaction`, `satisfaction_confidence` FROM `mindsdb`.`airline_data` WHERE ((`age` = 30))
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/classes/sql_query.py", line 68, in fetch
self._fetchData()
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/classes/sql_query.py", line 440, in _fetchData
came_from=self.integration
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py", line 220, in select
for f in model['data_analysis_v2']['columns']
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py", line 220, in <dictcomp>
for f in model['data_analysis_v2']['columns']
KeyError: 'typing'
'typing'

# Fixed code
def get(self, name):
    """List of predictors colums"""
    try:
        if is_custom(name):
            model = ca.custom_models.get_model_data(name)
        else:
            model = ca.mindsdb_native.get_model_data(name, native_view=True)
    except Exception:
        abort(404, "Invalid predictor name")

    columns = []
    for array, is_target_array in [
        (model["data_analysis"]["target_columns_metadata"], True),
        (model["data_analysis"]["input_columns_metadata"], False),
    ]:
        for col_data in array:
            column = {
                "name": col_data["column_name"],
                "data_type": col_data["data_type"].lower(),
                "is_target_column": is_target_array,
            }
            if column["data_type"] == "categorical":
                column["distribution"] = col_data["data_distribution"][
                    "data_histogram"
                ]["x"]
            columns.append(column)

    return columns, 200
# Buggy code
def get_model_data(self, name):
    return F.get_model_data(name)


# Traceback (KeyError)
'typing'
ERROR while fetching data for query: SELECT `satisfaction`, `satisfaction_confidence` FROM `mindsdb`.`airline_data` WHERE ((`age` = 30))
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/classes/sql_query.py", line 68, in fetch
self._fetchData()
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/classes/sql_query.py", line 440, in _fetchData
came_from=self.integration
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py", line 220, in select
for f in model['data_analysis_v2']['columns']
File "/home/zoran/MyProjects/mindsdb-examples/mdb/lib/python3.7/site-packages/mindsdb/api/mysql/mysql_proxy/datahub/datanodes/mindsdb_datanode.py", line 220, in <dictcomp>
for f in model['data_analysis_v2']['columns']
KeyError: 'typing'
'typing'

# Fixed code
def get_model_data(self, name, native_view=False):
    model = F.get_model_data(name)
    if native_view:
        return model

    data_analysis = model["data_analysis_v2"]
    for column in data_analysis["columns"]:
        if len(data_analysis[column]) == 0 or data_analysis[column].get(
            "empty", {}
        ).get("is_empty", False):
            data_analysis[column]["typing"] = {"data_subtype": DATA_SUBTYPES.INT}

    return model
# Buggy code
def on_file(file):
    data["file"] = file.file_name.decode()


# Traceback (PermissionError)
Exception on /datasources/Somedata [PUT] Traceback (most recent call last): File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\flask\app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\flask_restx\api.py", line 375, in wrapper resp = resource(*args, **kwargs) File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\flask\views.py", line 89, in view return self.dispatch_request(*args, **kwargs) File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\flask_restx\resource.py", line 44, in dispatch_request resp = meth(*args, **kwargs) File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\flask_restx\marshalling.py", line 248, in wrapper resp = f(*args, **kwargs) File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\mindsdb\api\http\namespaces\datasource.py", line 114, in put ca.default_store.save_datasource(ds_name, source_type, source, file_path) File "C:\Users\jp299\AppData\Roaming\mindsdb_gui\mindsdb_server\env\lib\site-packages\mindsdb\interfaces\datastore\datastore.py", line 81, in save_datasource os.replace(file_path, source) PermissionError: [WinError 32] El proceso no tiene acceso al archivo porque est� siendo utilizado por otro proceso: 'C:\\Users\\jp299\\AppData\\Local\\Temp\\datasource_file_pzpfjtzc\\Somedata.xlsx' -> 'C:\\Users\\jp299\\AppData\\Roaming\\mindsdb_gui\\mindsdb_server\\env\\lib\\site-packages/var/datastore\\Somedata\datasource\\Somedata.xlsx'

# Fixed code
def on_file(file):
    nonlocal file_object
    data["file"] = file.file_name.decode()
    file_object = file.file_object
# Buggy code
def unregister_predictor(self, name):
    q = f"""
            drop table if exists mindsdb.{name};
        """
    self._query(q)


# Traceback (Exception)
Using configuration file: config.json
Traceback (most recent call last):
File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/zoran/MyProjects/mindsdb/mindsdb/__main__.py", line 61, in <module>
dbw.register_predictors(model_data_arr)
File "/home/zoran/MyProjects/mindsdb/mindsdb/interfaces/database/database.py", line 41, in register_predictors
for integration in it: integration.register_predictors(model_data_arr)
File "/home/zoran/MyProjects/mindsdb/mindsdb/integrations/clickhouse/clickhouse.py", line 115, in register_predictors
self._query(q)
File "/home/zoran/MyProjects/mindsdb/mindsdb/integrations/clickhouse/clickhouse.py", line 58, in _query
raise Exception(f'Error: {response.content}\nQuery:{query}')
Exception: Error: b'Code: 62, e.displayText() = DB::Exception: Syntax error: failed at position 51 (line 2, col 50): -class\n                    ( `Number of times pregnant` Nullable(String) , `Plasma glucose concentration` Nullable(Int64) , `Diastolic blood pressure` Nullable(. Expected one of: storage definition, ENGINE, AS, UUID, OpeningRoundBracket, ON, Dot, token (version 20.5.2.7 (official build))\n'
Query:
CREATE TABLE mindsdb.diabetes-class
( `Number of times pregnant` Nullable(String) , `Plasma glucose concentration` Nullable(Int64) , `Diastolic blood pressure` Nullable(Int64) , `Triceps skin fold thickness` Nullable(Int64) , `2-Hour serum insulin` Nullable(Int64) , `Body mass index` Nullable(Float64) , `Diabetes pedigree function` Nullable(Float64) , `Age` Nullable(Int64) , `Class` Nullable(String) , `Class_original` Nullable(String) ,`select_data_query` Nullable(String),`Class_confidence` Nullable(Float64),`Class_explain` Nullable(String)
) ENGINE=MySQL('127.0.0.1:47335', 'mindsdb', 'diabetes-class_clickhouse', 'root', 'somepass')

# Fixed code
def unregister_predictor(self, name):
    q = f"""
            drop table if exists mindsdb.{self._escape_table_name(name)};
        """
    self._query(q)
# Buggy code
def initialize_interfaces(config, app):
    with app.app_context():
        g.default_store = DataStore(config)
        g.mindsdb_native = MindsdbNative(config)


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def initialize_interfaces(config, app):
    app.default_store = DataStore(config)
    app.mindsdb_native = MindsdbNative(config)
# Buggy code
def get(self):
    """List all datasources"""
    return g.default_store.get_datasources()


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def get(self):
    """List all datasources"""
    return ca.default_store.get_datasources()
# Buggy code
def get(self, name):
    """return datasource metadata"""
    ds = g.default_store.get_datasource(name)
    if ds is not None:
        return ds
    return "", 404


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def get(self, name):
    """return datasource metadata"""
    ds = ca.default_store.get_datasource(name)
    if ds is not None:
        return ds
    return "", 404
# Buggy code
def delete(self, name):
    """delete datasource"""
    try:
        g.default_store.delete_datasource(name)
    except Exception as e:
        print(e)
        abort(400, str(e))
    return "", 200


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def delete(self, name):
    """delete datasource"""
    try:
        ca.default_store.delete_datasource(name)
    except Exception as e:
        print(e)
        abort(400, str(e))
    return "", 200
# Buggy code
def get(self, name):
    ds = g.default_store.get_datasource(name)
    if ds is None:
        print("No valid datasource given")
        abort(400, "No valid datasource given")

    analysis = g.default_store.get_analysis(ds["source"])

    return analysis, 200


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def get(self, name):
    ds = ca.default_store.get_datasource(name)
    if ds is None:
        print("No valid datasource given")
        abort(400, "No valid datasource given")

    analysis = ca.default_store.get_analysis(ds["source"])

    return analysis, 200
# Buggy code
def get(self, name):
    ds = get_datasource(name)
    if ds is None:
        print("No valid datasource given")
        abort(400, "No valid datasource given")

    where = []
    for key, value in request.args.items():
        if key.startswith("filter"):
            param = parse_filter(key, value)
            if param is None:
                abort(400, f'Not valid filter "{key}"')
            where.append(param)

    data_dict = g.default_store.get_data(ds["name"], where)

    if data_dict["rowcount"] == 0:
        return abort(400, "Empty dataset after filters applying")

    return get_analysis(pd.DataFrame(data_dict["data"])), 200


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def get(self, name):
    ds = get_datasource(name)
    if ds is None:
        print("No valid datasource given")
        abort(400, "No valid datasource given")

    where = []
    for key, value in request.args.items():
        if key.startswith("filter"):
            param = parse_filter(key, value)
            if param is None:
                abort(400, f'Not valid filter "{key}"')
            where.append(param)

    data_dict = ca.default_store.get_data(ds["name"], where)

    if data_dict["rowcount"] == 0:
        return abort(400, "Empty dataset after filters applying")

    return get_analysis(pd.DataFrame(data_dict["data"])), 200
# Buggy code
def get(self, name):
    """download uploaded file"""
    ds = g.default_store.get_datasource(name)
    if not ds:
        abort(404, "{} not found".format(name))
    if not os.path.exists(ds["source"]):
        abort(404, "{} not found".format(name))

    return send_file(os.path.abspath(ds["source"]), as_attachment=True)


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def get(self, name):
    """download uploaded file"""
    ds = ca.default_store.get_datasource(name)
    if not ds:
        abort(404, "{} not found".format(name))
    if not os.path.exists(ds["source"]):
        abort(404, "{} not found".format(name))

    return send_file(os.path.abspath(ds["source"]), as_attachment=True)
# Buggy code
def get(self):
    """List all predictors"""

    return g.mindsdb_native.get_models()


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def get(self):
    """List all predictors"""

    return ca.mindsdb_native.get_models()
# Buggy code
def get(self, name):
    try:
        model = g.mindsdb_native.get_model_data(name)
    except Exception as e:
        abort(404, "")

    for k in ["train_end_at", "updated_at", "created_at"]:
        if k in model and model[k] is not None:
            model[k] = parse_datetime(model[k])

    return model


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def get(self, name):
    try:
        model = ca.mindsdb_native.get_model_data(name)
    except Exception as e:
        abort(404, "")

    for k in ["train_end_at", "updated_at", "created_at"]:
        if k in model and model[k] is not None:
            model[k] = parse_datetime(model[k])

    return model
# Buggy code
def delete(self, name):
    """Remove predictor"""
    g.mindsdb_native.delete_model(name)
    return "", 200


# Traceback (AttributeError)
2020-06-25 14:30:32,318 - INFO - Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335
2020-06-25 14:30:32,334 - INFO - Waiting for incoming connections...
127.0.0.1 - - [25/Jun/2020 14:31:14] "GET /util/ping HTTP/1.1" 200 -
Exception on /datasources/ [GET]
Traceback (most recent call last):
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
resp = resource(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/flask_restx/marshalling.py", line 248, in wrapper
resp = f(*args, **kwargs)
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/mindsdb/api/http/namespaces/datasource.py", line 40, in get
return g.default_store.get_datasources()
File "/home/zoran/MyProjects/mindsdb-examples/new/lib/python3.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'default_store'
127.0.0.1 - - [25/Jun/2020 14:31:18] "GET /datasources/ HTTP/1.1" 500 -
Exception on /datasources/ [GET]

# Fixed code
def delete(self, name):
    """Remove predictor"""
    ca.mindsdb_native.delete_model(name)
    return "", 200