gurudesh/pytracebugs huggingface dataset:
# Buggy code
def patch_all(
    socket=True,
    dns=True,
    time=True,
    select=True,
    thread=True,
    os=True,
    ssl=True,
    httplib=False,
    subprocess=False,
    sys=False,
    aggressive=True,
    Event=False,
):
    """Do all of the default monkey patching (calls every other function in this module."""
    # order is important
    if os:
        patch_os()
    if time:
        patch_time()
    if thread:
        patch_thread(Event=Event)
    # sys must be patched after thread. in other cases threading._shutdown will be
    # initiated to _MainThread with real thread ident
    if sys:
        patch_sys()
    if socket:
        patch_socket(dns=dns, aggressive=aggressive)
    if select:
        patch_select(aggressive=aggressive)
    if ssl:
        patch_ssl()
    if httplib:
        raise ValueError("gevent.httplib is no longer provided, httplib must be False")
    if subprocess:
        patch_subprocess()


# Traceback (TypeError)
python test.py
Traceback (most recent call last):
File "test.py", line 22, in <module>
TestFails()
File "test.py", line 19, in TestFails
sock.sendall(anStructure)
File "/usr/local/lib/python2.7/site-packages/gevent/socket.py", line 457, in sendall
while data_sent < len(data):
TypeError: object of type 'AnStructure' has no len()

# Fixed code
def patch_all(
    socket=True,
    dns=True,
    time=True,
    select=True,
    thread=True,
    os=True,
    ssl=True,
    httplib=False,
    subprocess=True,
    sys=False,
    aggressive=True,
    Event=False,
):
    """Do all of the default monkey patching (calls every other function in this module."""
    # order is important
    if os:
        patch_os()
    if time:
        patch_time()
    if thread:
        patch_thread(Event=Event)
    # sys must be patched after thread. in other cases threading._shutdown will be
    # initiated to _MainThread with real thread ident
    if sys:
        patch_sys()
    if socket:
        patch_socket(dns=dns, aggressive=aggressive)
    if select:
        patch_select(aggressive=aggressive)
    if ssl:
        patch_ssl()
    if httplib:
        raise ValueError("gevent.httplib is no longer provided, httplib must be False")
    if subprocess:
        patch_subprocess()
# Buggy code
def communicate(self, input=None):
    """Interact with process: Send data to stdin.  Read data from
    stdout and stderr, until end-of-file is reached.  Wait for
    process to terminate.  The optional input argument should be a
    string to be sent to the child process, or None, if no data
    should be sent to the child.

    communicate() returns a tuple (stdout, stderr)."""
    greenlets = []
    if self.stdin:
        greenlets.append(spawn(write_and_close, self.stdin, input))

    if self.stdout:
        stdout = spawn(self.stdout.read)
        greenlets.append(stdout)
    else:
        stdout = None

    if self.stderr:
        stderr = spawn(self.stderr.read)
        greenlets.append(stderr)
    else:
        stderr = None

    joinall(greenlets)

    if self.stdout:
        self.stdout.close()
    if self.stderr:
        self.stderr.close()

    self.wait()
    return (
        None if stdout is None else stdout.value or "",
        None if stderr is None else stderr.value or "",
    )


# Traceback (TypeError)
python test.py
Traceback (most recent call last):
File "test.py", line 22, in <module>
TestFails()
File "test.py", line 19, in TestFails
sock.sendall(anStructure)
File "/usr/local/lib/python2.7/site-packages/gevent/socket.py", line 457, in sendall
while data_sent < len(data):
TypeError: object of type 'AnStructure' has no len()

# Fixed code
def communicate(self, input=None):
    """Interact with process: Send data to stdin.  Read data from
    stdout and stderr, until end-of-file is reached.  Wait for
    process to terminate.  The optional input argument should be a
    string to be sent to the child process, or None, if no data
    should be sent to the child.

    communicate() returns a tuple (stdout, stderr)."""
    greenlets = []
    if self.stdin:
        greenlets.append(spawn(write_and_close, self.stdin, input))

    if self.stdout:
        stdout = spawn(self.stdout.read)
        greenlets.append(stdout)
    else:
        stdout = None

    if self.stderr:
        stderr = spawn(self.stderr.read)
        greenlets.append(stderr)
    else:
        stderr = None

    joinall(greenlets)

    if self.stdout:
        self.stdout.close()
    if self.stderr:
        self.stderr.close()

    self.wait()
    return (
        None if stdout is None else stdout.value or b"",
        None if stderr is None else stderr.value or b"",
    )
# Buggy code
def get_annotations(self, tag, issue, issue_obj, url):
    response = self.get_data(
        self.BASE_API + "/repositories/%s/issues/%i/comments" % (tag, issue["id"])
    )
    return self.build_annotations(
        (
            (
                comment["author_info"]["username"],
                comment["content"],
            )
            for comment in response
        ),
        issue_obj.get_processed_url(url),
    )


# Traceback (IOError)
ERROR:bugwarrior.services:Worker for [ELIDED] failed: Non-200 status code 410; u'https://api.bitbucket.org/1.0/repositories/[ELIDED]'; u'{"type": "error", "error": {"message": "Resource removed", "detail": "This API is no longer supported.\\n\\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"}}'
Traceback (most recent call last):
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 499, in _aggregate_issues
for issue in service.issues():
File "/home/ELIDEDi/.local/lib/python2.7/site-packages/bugwarrior/services/bitbucket.py", line 233, in issues
'annotations': self.get_annotations(tag, issue, issue_obj, url)
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/bitbucket.py", line 177, in get_annotations
'/repositories/%s/issues/%i/comments' % (tag, issue['id']))
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/bitbucket.py", line 144, in get_data
return self.json_response(requests.get(url, **self.requests_kwargs))
File "/home/ELIDED/.local/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 478, in json_response
response.status_code, response.url, response.text,
IOError: Non-200 status code 410; u'https://api.bitbucket.org/1.0/repositories/ELIDED'; u'{"type": "error", "error": {"message": "Resource removed", "detail": "This API is no longer supported.\\n\\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"}}'

# Fixed code
def get_annotations(self, tag, issue, issue_obj, url):
    response = self.get_collection(
        "/repositories/%s/pullrequests/%i/comments" % (tag, issue["id"])
    )
    return self.build_annotations(
        (
            (
                comment["user"]["username"],
                comment["content"]["raw"],
            )
            for comment in response
        ),
        issue_obj.get_processed_url(url),
    )
# Buggy code
def to_taskwarrior(self):
    return {
        "project": self.extra["project"],
        "annotations": self.extra["annotations"],
        self.URL: self.extra["url"],
        "priority": self.origin["default_priority"],
        "tags": self.record["tags"],
        self.FOREIGN_ID: self.record["ref"],
        self.SUMMARY: self.record["subject"],
    }


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/local/bin/bugwarrior-pull", line 11, in <module>
sys.exit(pull())
File "/home/frank/.local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/frank/.local/lib/python2.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/frank/.local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/frank/.local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/frank/.local/lib/python2.7/site-packages/bugwarrior/command.py", line 73, in pull
synchronize(issue_generator, config, main_section, dry_run)
File "/home/frank/.local/lib/python2.7/site-packages/bugwarrior/db.py", line 386, in synchronize
send_notification(issue, 'Created', conf)
File "/home/frank/.local/lib/python2.7/site-packages/bugwarrior/notifications.py", line 111, in send_notification
metadata = _get_metadata(issue)
File "/home/frank/.local/lib/python2.7/site-packages/bugwarrior/notifications.py", line 39, in _get_metadata
tags = "Tags: " + ', '.join(issue['tags'])
TypeError: sequence item 0: expected string, list found

# Fixed code
def to_taskwarrior(self):
    return {
        "project": self.extra["project"],
        "annotations": self.extra["annotations"],
        self.URL: self.extra["url"],
        "priority": self.origin["default_priority"],
        "tags": self.get_tags(),
        self.FOREIGN_ID: self.record["ref"],
        self.SUMMARY: self.record["subject"],
    }
# Buggy code
def _get_bug_attr(bug, attr):
    """Default only the longdescs case to [] since it may not be present."""
    if attr == "longdescs":
        return getattr(bug, attr, [])
    return getattr(bug, attr)


# Traceback (AttributeError)
ERROR:bugwarrior.services:Worker for [bz.redhat] failed: Bug object has no attribute 'flags'.
If 'flags' is a bugzilla attribute, it may not have been cached when the bug was fetched. You may want to adjust your include_fields for getbug/query.
Traceback (most recent call last):
File "/home/mike/Devel/bugwarrior/build/lib/bugwarrior/services/__init__.py", line 506, in _aggregate_issues
for issue in service.issues():
File "/home/mike/Devel/bugwarrior/build/lib/bugwarrior/services/bz.py", line 257, in issues
) for bug in bugs
File "/home/mike/Devel/bugwarrior/build/lib/bugwarrior/services/bz.py", line 256, in <genexpr>
((col, _get_bug_attr(bug, col)) for col in self.COLUMN_LIST)
File "/home/mike/Devel/bugwarrior/build/lib/bugwarrior/services/bz.py", line 291, in _get_bug_attr
return getattr(bug, attr)
File "/usr/lib/python2.7/site-packages/bugzilla/bug.py", line 110, in __getattr__
raise AttributeError(msg)
AttributeError: Bug object has no attribute 'flags'.
If 'flags' is a bugzilla attribute, it may not have been cached when the bug was fetched. You may want to adjust your include_fields for getbug/query.
INFO:bugwarrior.services:Done with [bz.redhat] in 7.013321s

# Fixed code
def _get_bug_attr(bug, attr):
    """Default longdescs/flags case to [] since they may not be present."""
    if attr in ("longdescs", "flags"):
        return getattr(bug, attr, [])
    return getattr(bug, attr)
# Buggy code
def run_hooks(conf, name):
    if conf.has_option("hooks", name):
        pre_import = [t.strip() for t in conf.get("hooks", name).split(",")]
        if pre_import is not None:
            for hook in pre_import:
                exit_code = subprocess.call(hook, shell=True)
                if exit_code is not 0:
                    msg = "Non-zero exit code %d on hook %s" % (exit_code, hook)
                    log.error(msg)
                    raise RuntimeError(msg)


# Traceback (KeyError)
Traceback (most recent call last):
File "/usr/local/bin/bugwarrior-pull", line 11, in <module>
load_entry_point('bugwarrior==1.5.1', 'console_scripts', 'bugwarrior-pull')()
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 700, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 680, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 508, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/bugwarrior-1.5.1-py2.7.egg/bugwarrior/command.py", line 73, in pull
synchronize(issue_generator, config, main_section, dry_run)
File "/usr/local/lib/python2.7/dist-packages/bugwarrior-1.5.1-py2.7.egg/bugwarrior/db.py", line 351, in synchronize
del issue_dict[field]
KeyError: u' description'

# Fixed code
def run_hooks(conf, name):
    if conf.has_option("hooks", name):
        pre_import = aslist(conf.get("hooks", name))
        if pre_import is not None:
            for hook in pre_import:
                exit_code = subprocess.call(hook, shell=True)
                if exit_code is not 0:
                    msg = "Non-zero exit code %d on hook %s" % (exit_code, hook)
                    log.error(msg)
                    raise RuntimeError(msg)
# Buggy code
def get_defined_udas_as_strings(conf, main_section):
    targets = [t.strip() for t in conf.get(main_section, "targets").split(",")]
    services = set([conf.get(target, "service") for target in targets])
    uda_list = build_uda_config_overrides(services)

    for uda in convert_override_args_to_taskrc_settings(uda_list):
        yield uda


# Traceback (KeyError)
Traceback (most recent call last):
File "/usr/local/bin/bugwarrior-pull", line 11, in <module>
load_entry_point('bugwarrior==1.5.1', 'console_scripts', 'bugwarrior-pull')()
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 700, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 680, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 508, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/bugwarrior-1.5.1-py2.7.egg/bugwarrior/command.py", line 73, in pull
synchronize(issue_generator, config, main_section, dry_run)
File "/usr/local/lib/python2.7/dist-packages/bugwarrior-1.5.1-py2.7.egg/bugwarrior/db.py", line 351, in synchronize
del issue_dict[field]
KeyError: u' description'

# Fixed code
def get_defined_udas_as_strings(conf, main_section):
    targets = aslist(conf.get(main_section, "targets"))
    services = set([conf.get(target, "service") for target in targets])
    uda_list = build_uda_config_overrides(services)

    for uda in convert_override_args_to_taskrc_settings(uda_list):
        yield uda
# Buggy code
def add(
    general_config,
    host_address,
    login_name,
    key_path,
    ssh_port,
    host_nickname,
    namespace,
    network,
):
    """Adds an existing node to the local config for future management."""

    emitter = setup_emitter(general_config)
    name = f"{namespace}-{network}-{host_nickname}"

    deployer = CloudDeployers.get_deployer("generic")(
        emitter, None, None, namespace=namespace, network=network, action="add"
    )
    config = deployer.create_nodes([name], host_address, login_name, key_path, ssh_port)
    emitter.echo(
        f"Success.  Now run `nucypher cloudworkers deploy --namespace {namespace} --remote-provider <an eth provider>` to deploy Nucypher on this node.",
        color="green",
    )


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
TypeError: add_for_stake() got an unexpected keyword argument 'config_file'

# Fixed code
def add(
    general_config,
    host_address,
    login_name,
    key_path,
    ssh_port,
    host_nickname,
    namespace,
    network,
):
    """Adds an existing node to the local config for future management."""

    emitter = setup_emitter(general_config)
    name = host_nickname

    deployer = CloudDeployers.get_deployer("generic")(
        emitter, None, None, namespace=namespace, network=network, action="add"
    )
    config = deployer.create_nodes([name], host_address, login_name, key_path, ssh_port)
    emitter.echo(
        f"Success.  Now run `nucypher cloudworkers deploy --namespace {namespace} --remote-provider <an eth provider>` to deploy Nucypher on this node.",
        color="green",
    )
# Buggy code
def network_config_path(self):
    return os.path.join(DEFAULT_CONFIG_ROOT, NODE_CONFIG_STORAGE_KEY, self.network)


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
TypeError: add_for_stake() got an unexpected keyword argument 'config_file'

# Fixed code
def network_config_path(self):
    return Path(DEFAULT_CONFIG_ROOT).joinpath(NODE_CONFIG_STORAGE_KEY, self.network)
# Buggy code
def inventory_path(self):
    return os.path.join(
        DEFAULT_CONFIG_ROOT,
        NODE_CONFIG_STORAGE_KEY,
        f"{self.namespace_network}.ansible_inventory.yml",
    )


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
TypeError: add_for_stake() got an unexpected keyword argument 'config_file'

# Fixed code
def inventory_path(self):
    return str(
        Path(DEFAULT_CONFIG_ROOT).joinpath(
            NODE_CONFIG_STORAGE_KEY, f"{self.namespace_network}.ansible_inventory.yml"
        )
    )
# Buggy code
def backup_remote_data(self, node_names):
    playbook = "deploy/ansible/worker/backup_remote_workers.yml"
    self.generate_ansible_inventory(node_names)

    loader = DataLoader()
    inventory = InventoryManager(loader=loader, sources=self.inventory_path)
    callback = AnsiblePlayBookResultsCollector(
        sock=self.emitter, return_results=self.output_capture
    )
    variable_manager = VariableManager(loader=loader, inventory=inventory)

    executor = PlaybookExecutor(
        playbooks=[playbook],
        inventory=inventory,
        variable_manager=variable_manager,
        loader=loader,
        passwords=dict(),
    )
    executor._tqm._stdout_callback = callback
    executor.run()

    self.give_helpful_hints(node_names, backup=True, playbook=playbook)


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
TypeError: add_for_stake() got an unexpected keyword argument 'config_file'

# Fixed code
def backup_remote_data(self, node_names):
    playbook = Path(DEPLOY_DIR).joinpath("ansible/worker/backup_remote_workers.yml")
    self.update_generate_inventory(node_names)

    loader = DataLoader()
    inventory = InventoryManager(loader=loader, sources=self.inventory_path)
    callback = AnsiblePlayBookResultsCollector(
        sock=self.emitter, return_results=self.output_capture
    )
    variable_manager = VariableManager(loader=loader, inventory=inventory)

    executor = PlaybookExecutor(
        playbooks=[playbook],
        inventory=inventory,
        variable_manager=variable_manager,
        loader=loader,
        passwords=dict(),
    )
    executor._tqm._stdout_callback = callback
    executor.run()

    self.give_helpful_hints(node_names, backup=True, playbook=playbook)
# Buggy code
def _create_keypair(self):
    new_keypair_data = self.ec2Client.create_key_pair(
        KeyName=f"{self.namespace_network}"
    )
    outpath = os.path.join(
        DEFAULT_CONFIG_ROOT,
        NODE_CONFIG_STORAGE_KEY,
        f"{self.namespace_network}.awskeypair",
    )
    os.makedirs(os.path.dirname(outpath), exist_ok=True)
    with open(outpath, "w") as outfile:
        outfile.write(new_keypair_data["KeyMaterial"])
    # set local keypair permissions https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
    os.chmod(outpath, 0o400)
    self.emitter.echo(
        f"a new aws keypair was saved to {outpath}, keep it safe.", color="yellow"
    )
    return new_keypair_data["KeyName"], outpath


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
TypeError: add_for_stake() got an unexpected keyword argument 'config_file'

# Fixed code
def _create_keypair(self):
    new_keypair_data = self.ec2Client.create_key_pair(
        KeyName=f"{self.namespace_network}"
    )
    outpath = Path(DEFAULT_CONFIG_ROOT).joinpath(
        NODE_CONFIG_STORAGE_KEY, f"{self.namespace_network}.awskeypair"
    )
    os.makedirs(os.path.dirname(outpath), exist_ok=True)
    with open(outpath, "w") as outfile:
        outfile.write(new_keypair_data["KeyMaterial"])
    # set local keypair permissions https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
    os.chmod(outpath, 0o400)
    self.emitter.echo(
        f"a new aws keypair was saved to {outpath}, keep it safe.", color="yellow"
    )
    return new_keypair_data["KeyName"], outpath
# Buggy code
def _delete_keypair(self):
    # only use self.namespace here to avoid accidental deletions of pre-existing keypairs
    deleted_keypair_data = self.ec2Client.delete_key_pair(
        KeyName=f"{self.namespace_network}"
    )
    if deleted_keypair_data["HTTPStatusCode"] == 200:
        outpath = os.path.join(
            DEFAULT_CONFIG_ROOT,
            NODE_CONFIG_STORAGE_KEY,
            f"{self.namespace_network}.awskeypair",
        )
        os.remove(outpath)
        self.emitter.echo(f"keypair at {outpath}, was deleted", color="yellow")


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/k/.local/share/virtualenvs/nucypher-iNjwDRsw/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
File "/home/k/Git/nucypher/nucypher/cli/options.py", line 167, in wrapper
return func(**kwargs)
TypeError: add_for_stake() got an unexpected keyword argument 'config_file'

# Fixed code
def _delete_keypair(self):
    # only use self.namespace here to avoid accidental deletions of pre-existing keypairs
    deleted_keypair_data = self.ec2Client.delete_key_pair(
        KeyName=f"{self.namespace_network}"
    )
    if deleted_keypair_data["HTTPStatusCode"] == 200:
        outpath = Path(DEFAULT_CONFIG_ROOT).joinpath(
            NODE_CONFIG_STORAGE_KEY, f"{self.namespace_network}.awskeypair"
        )
        os.remove(outpath)
        self.emitter.echo(f"keypair at {outpath}, was deleted", color="yellow")
# Buggy code
def config(general_config, config_options, config_file):
    """View and optionally update the Ursula node's configuration."""
    emitter = setup_emitter(general_config, config_options.worker_address)
    if not config_file:
        config_file = select_config_file(
            emitter=emitter,
            checksum_address=config_options.worker_address,
            config_class=UrsulaConfiguration,
        )
    emitter.echo(f"Ursula Configuration {config_file} \n {'=' * 55}")
    updates = config_options.get_updates()
    get_or_update_configuration(
        emitter=emitter,
        config_class=UrsulaConfiguration,
        filepath=config_file,
        updates=updates,
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/tux/code/nucypher-prod/venv/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
[Previous line repeated 1 more time]
File "/home/tux/code/nucypher-prod/nucypher/cli/commands/stake.py", line 1263, in set_min_rate
paint_min_rate(emitter, STAKEHOLDER.registry, STAKEHOLDER.policy_agent, staking_address)
File "/home/tux/code/nucypher-prod/nucypher/cli/painting/staking.py", line 229, in paint_min_rate
minimum = policy_agent.min_fee_rate(staker_address)
AttributeError: 'PolicyManagerAgent' object has no attribute 'min_fee_rate'

# Fixed code
def config(general_config, config_options, config_file):
    """View and optionally update the Ursula node's configuration."""
    emitter = setup_emitter(general_config, config_options.worker_address)
    if not config_file:
        config_file = select_config_file(
            emitter=emitter,
            checksum_address=config_options.worker_address,
            config_class=UrsulaConfiguration,
        )
    updates = config_options.get_updates()
    get_or_update_configuration(
        emitter=emitter,
        config_class=UrsulaConfiguration,
        filepath=config_file,
        updates=updates,
    )
# Buggy code
def paint_min_rate(emitter, registry, policy_agent, staker_address):
    paint_fee_rate_range(emitter, policy_agent)
    minimum = policy_agent.min_fee_rate(staker_address)
    raw_minimum = policy_agent.raw_min_fee_rate(staker_address)

    rate_payload = f"""
Minimum acceptable fee rate (set by staker for their associated worker):
    ~ Previously set ....... {prettify_eth_amount(raw_minimum)}
    ~ Effective ............ {prettify_eth_amount(minimum)}"""
    emitter.echo(rate_payload)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/tux/code/nucypher-prod/venv/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
[Previous line repeated 1 more time]
File "/home/tux/code/nucypher-prod/nucypher/cli/commands/stake.py", line 1263, in set_min_rate
paint_min_rate(emitter, STAKEHOLDER.registry, STAKEHOLDER.policy_agent, staking_address)
File "/home/tux/code/nucypher-prod/nucypher/cli/painting/staking.py", line 229, in paint_min_rate
minimum = policy_agent.min_fee_rate(staker_address)
AttributeError: 'PolicyManagerAgent' object has no attribute 'min_fee_rate'

# Fixed code
def paint_min_rate(emitter, staker):
    paint_fee_rate_range(emitter, staker.policy_agent)
    minimum = staker.min_fee_rate
    raw_minimum = staker.raw_min_fee_rate

    rate_payload = f"""
Minimum acceptable fee rate (set by staker for their associated worker):
    ~ Previously set ....... {prettify_eth_amount(raw_minimum)}
    ~ Effective ............ {prettify_eth_amount(minimum)}"""
    emitter.echo(rate_payload)
# Buggy code
def _discover_or_abort(_first_result):
    self.log.debug(f"{self} learning at {datetime.datetime.now()}")
    result = self.learn_from_teacher_node(
        eager=False, canceller=self._discovery_canceller
    )
    self.log.debug(f"{self} finished learning at {datetime.datetime.now()}")
    return result


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/tux/code/nucypher-prod/venv/bin/nucypher", line 33, in <module>
sys.exit(load_entry_point('nucypher', 'console_scripts', 'nucypher')())
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/tux/code/nucypher-prod/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
File "/home/tux/code/nucypher-prod/nucypher/cli/options.py", line 163, in wrapper
return func(**kwargs)
[Previous line repeated 1 more time]
File "/home/tux/code/nucypher-prod/nucypher/cli/commands/stake.py", line 1263, in set_min_rate
paint_min_rate(emitter, STAKEHOLDER.registry, STAKEHOLDER.policy_agent, staking_address)
File "/home/tux/code/nucypher-prod/nucypher/cli/painting/staking.py", line 229, in paint_min_rate
minimum = policy_agent.min_fee_rate(staker_address)
AttributeError: 'PolicyManagerAgent' object has no attribute 'min_fee_rate'

# Fixed code
def _discover_or_abort(_first_result):
    # self.log.debug(f"{self} learning at {datetime.datetime.now()}")   # 1712
    result = self.learn_from_teacher_node(
        eager=False, canceller=self._discovery_canceller
    )
    # self.log.debug(f"{self} finished learning at {datetime.datetime.now()}")  # 1712
    return result
# Buggy code
def __getitem__(self, event_name: str):
    event_method = self.__get_web3_event_by_name(event_name)

    def wrapper(from_block=None, to_block=None, **argument_filters):
        if from_block is None:
            from_block = 0  # TODO: we can do better. Get contract creation block.
        if to_block is None:
            to_block = "latest"

        event_filter = event_method.createFilter(
            fromBlock=from_block, toBlock=to_block, argument_filters=argument_filters
        )
        entries = event_filter.get_all_entries()
        for entry in entries:
            yield EventRecord(entry)

    return wrapper


# Traceback (builtins.ValueError)
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical] Unhandled error in Deferred:
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical]
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1283, in run
self.mainLoop()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1292, in mainLoop
self.runUntilCurrent()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 913, in runUntilCurrent
call.func(*call.args, call.kw)
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/task.py", line 239, in call
d = defer.maybeDeferred(self.f, *self.a, self.kw)
--- <exception caught here> ---
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/defer.py", line 151, in maybeDeferred
result = f(*args, **kw)
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/metrics.py", line 147, in collect_prometheus_metrics
collector.collect()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 77, in collect
self._collect_internal()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 303, in _collect_internal
events = self.event_filter.get_new_entries()
File "/usr/local/lib/python3.6/dist-packages/web3/_utils/filters.py", line 159, in get_new_entries
log_entries = self._filter_valid_entries(self.web3.eth.getFilterChanges(self.filter_id))
File "/usr/local/lib/python3.6/dist-packages/web3/eth.py", line 493, in getFilterChanges
RPC.eth_getFilterChanges, [filter_id],
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 153, in request_blocking
raise ValueError(response["error"])
builtins.ValueError: {'code': -32000, 'message': 'filter not found'}

# Fixed code
def __getitem__(self, event_name: str):
    event_method = self.__get_web3_event_by_name(event_name)

    def wrapper(from_block=None, to_block=None, **argument_filters):
        if from_block is None:
            from_block = 0  # TODO: we can do better. Get contract creation block.
        if to_block is None:
            to_block = "latest"

        entries = event_method.getLogs(
            fromBlock=from_block, toBlock=to_block, argument_filters=argument_filters
        )
        for entry in entries:
            yield EventRecord(entry)

    return wrapper
# Buggy code
def wrapper(from_block=None, to_block=None, **argument_filters):
    if from_block is None:
        from_block = 0  # TODO: we can do better. Get contract creation block.
    if to_block is None:
        to_block = "latest"

    event_filter = event_method.createFilter(
        fromBlock=from_block, toBlock=to_block, argument_filters=argument_filters
    )
    entries = event_filter.get_all_entries()
    for entry in entries:
        yield EventRecord(entry)


# Traceback (builtins.ValueError)
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical] Unhandled error in Deferred:
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical]
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1283, in run
self.mainLoop()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1292, in mainLoop
self.runUntilCurrent()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 913, in runUntilCurrent
call.func(*call.args, call.kw)
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/task.py", line 239, in call
d = defer.maybeDeferred(self.f, *self.a, self.kw)
--- <exception caught here> ---
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/defer.py", line 151, in maybeDeferred
result = f(*args, **kw)
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/metrics.py", line 147, in collect_prometheus_metrics
collector.collect()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 77, in collect
self._collect_internal()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 303, in _collect_internal
events = self.event_filter.get_new_entries()
File "/usr/local/lib/python3.6/dist-packages/web3/_utils/filters.py", line 159, in get_new_entries
log_entries = self._filter_valid_entries(self.web3.eth.getFilterChanges(self.filter_id))
File "/usr/local/lib/python3.6/dist-packages/web3/eth.py", line 493, in getFilterChanges
RPC.eth_getFilterChanges, [filter_id],
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 153, in request_blocking
raise ValueError(response["error"])
builtins.ValueError: {'code': -32000, 'message': 'filter not found'}

# Fixed code
def wrapper(from_block=None, to_block=None, **argument_filters):
    if from_block is None:
        from_block = 0  # TODO: we can do better. Get contract creation block.
    if to_block is None:
        to_block = "latest"

    entries = event_method.getLogs(
        fromBlock=from_block, toBlock=to_block, argument_filters=argument_filters
    )
    for entry in entries:
        yield EventRecord(entry)
# Buggy code
def __init__(
    self,
    event_name: str,
    event_args_config: Dict[str, tuple],
    argument_filters: Dict[str, str],
    contract_agent: ContractAgents,
):
    super().__init__()
    self.event_name = event_name
    self.contract_agent = contract_agent
    self.event_filter = contract_agent.contract.events[event_name].createFilter(
        fromBlock="latest", argument_filters=argument_filters
    )
    self.event_args_config = event_args_config


# Traceback (builtins.ValueError)
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical] Unhandled error in Deferred:
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical]
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1283, in run
self.mainLoop()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1292, in mainLoop
self.runUntilCurrent()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 913, in runUntilCurrent
call.func(*call.args, call.kw)
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/task.py", line 239, in call
d = defer.maybeDeferred(self.f, *self.a, self.kw)
--- <exception caught here> ---
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/defer.py", line 151, in maybeDeferred
result = f(*args, **kw)
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/metrics.py", line 147, in collect_prometheus_metrics
collector.collect()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 77, in collect
self._collect_internal()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 303, in _collect_internal
events = self.event_filter.get_new_entries()
File "/usr/local/lib/python3.6/dist-packages/web3/_utils/filters.py", line 159, in get_new_entries
log_entries = self._filter_valid_entries(self.web3.eth.getFilterChanges(self.filter_id))
File "/usr/local/lib/python3.6/dist-packages/web3/eth.py", line 493, in getFilterChanges
RPC.eth_getFilterChanges, [filter_id],
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 153, in request_blocking
raise ValueError(response["error"])
builtins.ValueError: {'code': -32000, 'message': 'filter not found'}

# Fixed code
def __init__(
    self,
    event_name: str,
    event_args_config: Dict[str, tuple],
    argument_filters: Dict[str, str],
    contract_agent: ContractAgents,
):
    super().__init__()
    self.event_name = event_name
    self.contract_agent = contract_agent

    # this way we don't have to deal with 'latest' at all
    self.filter_current_from_block = self.contract_agent.blockchain.client.block_number
    self.filter_arguments = argument_filters
    self.event_args_config = event_args_config