Validating arguments against arg spec: Importing 'AnsibleFilterTypeError' is deprecated

I’m starting to test some roles using fallible and I don’t understand what this deprecation warning means?

TASK [apt : Validating arguments against arg spec 'main'] **********************************************************************************************************************************************************************************************************************
[DEPRECATION WARNING]: Importing 'AnsibleFilterTypeError' is deprecated. This feature will be removed from the 'ansible.builtin.validate_argument_spec' action plugin (requested as 'ansible_collections.ansible.builtin.plugins.action.validate_argument_spec') in version 2.23. Import 'AnsibleTypeError' instead.

Can anyone shed any light on this? Should I simply ignore it?

It you set the env var ANSIBLE_DISPLAY_TRACEBACK to deprecated, you should be able to see the specific filter plugin file that’s importing the deprecated error type.

1 Like

Thanks @shertel I’m not sure how to find that from the results? What exactly am I looking for?

[DEPRECATION WARNING]: Importing 'AnsibleFilterTypeError' is deprecated. This feature will be removed in version 2.23. Import 'AnsibleTypeError' instead.

Traceback (most recent call last):
  File "/home/chris/.local/bin/fallible-playbook", line 8, in <module>
    sys.exit(main())
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/cli/playbook.py", line 229, in main
    PlaybookCLI.cli_executor(args)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/cli/__init__.py", line 650, in cli_executor
    exit_code = cli.run()
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/cli/playbook.py", line 151, in run
    results = pbex.run()
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/playbook_executor.py", line 188, in run
    result = self._tqm.run(play=play)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/task_queue_manager.py", line 370, in run
    play_return = strategy.run(iterator, play_context)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/strategy/linear.py", line 193, in run
    self._queue_task(host, task, task_vars, play_context)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/strategy/__init__.py", line 390, in _queue_task
    worker_prc.start()
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/process/worker.py", line 126, in start
    super(WorkerProcess, self).start()
  File "/usr/lib/python3.11/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/usr/lib/python3.11/multiprocessing/context.py", line 281, in _Popen
    return Popen(process_obj)
  File "/usr/lib/python3.11/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/usr/lib/python3.11/multiprocessing/popen_fork.py", line 71, in _launch
    code = process_obj._bootstrap(parent_sentinel=child_r)
  File "/usr/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/process/worker.py", line 195, in run
    return self._run()
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/process/worker.py", line 240, in _run
    ).run()
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/task_executor.py", line 167, in run
    res = self._execute(self._task_templar, self._job_vars)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/task_executor.py", line 439, in _execute
    result = self._execute_internal(templar, variables)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/executor/task_executor.py", line 548, in _execute_internal
    self._task.post_validate(templar=templar)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/playbook/task.py", line 354, in post_validate
    super(Task, self).post_validate(templar)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/playbook/base.py", line 533, in post_validate
    value = self.post_validate_attribute(name, templar=templar)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/playbook/base.py", line 582, in post_validate_attribute
    value = method(attribute, getattr(self, name), templar)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/playbook/task.py", line 196, in _post_validate_args
    args = args_finalizer.finalize(action_type.finalize_task_arg, context=finalize_context)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_task.py", line 78, in finalize
    return ct.as_dict()
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_chain_templar.py", line 63, in as_dict
    return dict(self.items())
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_chain_templar.py", line 57, in items
    yield key, self.get(key)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_chain_templar.py", line 35, in get
    return self.template(key, value)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_task.py", line 45, in template
    return self.callback(key, value, self.templar, self.context)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/action/assert.py", line 35, in finalize_task_arg
    return super().finalize_task_arg(name, value, templar, context)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/action/__init__.py", line 233, in finalize_task_arg
    return templar.template(value)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_engine.py", line 284, in template
    template_result = compiled_template(self.available_variables)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_bits.py", line 312, in __call__
    return self.render(ArgSmuggler.package_jinja_vars(jinja_vars))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/environment.py", line 1293, in render
    return self.environment.concat(self.root_render_func(ctx))  # type: ignore
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_bits.py", line 696, in concat
    node_list = list(_flatten_nodes(nodes))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_bits.py", line 837, in _flatten_nodes
    node = next(iterator)
  File "<template>", line 10, in root
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/runtime.py", line 243, in resolve_or_missing
    return self.parent[key]
  File "/usr/lib/python3.11/collections/__init__.py", line 1001, in __getitem__
    return mapping[key]             # can't use 'key in mapping' with defaultdict
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_lazy_containers.py", line 248, in __getitem__
    return self._proxy_or_render_lazy_value(key, super().__getitem__(key))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_lazy_containers.py", line 216, in _proxy_or_render_lazy_value
    new_value = self._templar.template(original_value, lazy_options=self._lazy_options)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_engine.py", line 284, in template
    template_result = compiled_template(self.available_variables)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_bits.py", line 312, in __call__
    return self.render(ArgSmuggler.package_jinja_vars(jinja_vars))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/environment.py", line 1293, in render
    return self.environment.concat(self.root_render_func(ctx))  # type: ignore
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_bits.py", line 696, in concat
    node_list = list(_flatten_nodes(nodes))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_bits.py", line 837, in _flatten_nodes
    node = next(iterator)
  File "<template>", line 12, in root
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/runtime.py", line 243, in resolve_or_missing
    return self.parent[key]
  File "/usr/lib/python3.11/collections/__init__.py", line 1001, in __getitem__
    return mapping[key]             # can't use 'key in mapping' with defaultdict
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_lazy_containers.py", line 248, in __getitem__
    return self._proxy_or_render_lazy_value(key, super().__getitem__(key))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_lazy_containers.py", line 216, in _proxy_or_render_lazy_value
    new_value = self._templar.template(original_value, lazy_options=self._lazy_options)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_engine.py", line 282, in template
    compiled_template = self._compile_template(variable, options)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_engine.py", line 364, in _compile_template
    return t.cast(AnsibleTemplate, env.from_string(stripped_template))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_bits.py", line 652, in from_string
    template_obj = t.cast(AnsibleTemplate, super().from_string(source, *args, **kwargs))
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/environment.py", line 1111, in from_string
    return cls.from_code(self, self.compile(source), gs, None)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/environment.py", line 764, in compile
    source = self._generate(source, name, filename, defer_init=defer_init)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/environment.py", line 694, in _generate
    return generate(  # type: ignore
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 117, in generate
    generator.visit(node)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/visitor.py", line 40, in visit
    return f(node, *args, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 892, in visit_Template
    self.blockvisit(node.body, frame)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 449, in blockvisit
    self.visit(node, frame)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/visitor.py", line 40, in visit
    return f(node, *args, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 1569, in visit_Output
    self.visit(item, frame)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/visitor.py", line 40, in visit
    return f(node, *args, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 56, in new_func
    return f(self, node, frame, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 1842, in visit_Filter
    self.visit(node.node, frame)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/visitor.py", line 40, in visit
    return f(node, *args, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 56, in new_func
    return f(self, node, frame, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 1842, in visit_Filter
    self.visit(node.node, frame)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/visitor.py", line 40, in visit
    return f(node, *args, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 56, in new_func
    return f(self, node, frame, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 1838, in visit_Filter
    with self._filter_test_common(node, frame, True):
  File "/usr/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/jinja2/compiler.py", line 1803, in _filter_test_common
    func = self.environment.filters.get(node.name)
  File "<frozen _collections_abc>", line 774, in get
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/_internal/_templating/_jinja_plugins.py", line 71, in __getitem__
    instance = self._plugin_loader.get(key)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/loader.py", line 906, in get
    ctx = self.get_with_context(name, *args, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/loader.py", line 1387, in get_with_context
    plugin_impl = super(Jinja2Loader, self).get_with_context(module_name, *args, **kwargs)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/loader.py", line 950, in get_with_context
    self._module_cache[path] = self._load_module_source(resolved_type_name, path)
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/plugins/loader.py", line 871, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/chris/.ansible/collections/ansible_collections/community/general/plugins/filter/hashids.py", line 9, in <module>
    from ansible.errors import (
  File "<frozen importlib._bootstrap>", line 1231, in _handle_fromlist
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/errors/__init__.py", line 422, in __getattr__
    Display().deprecated(
  File "/home/chris/.local/pipx/venvs/fallible/lib/python3.11/site-packages/fallible/_vendor/ansible/lib/ansible/utils/display.py", line 675, in deprecated
    self._deprecated_with_plugin_info(
File "/home/chris/.ansible/collections/ansible_collections/community/general/plugins/filter/hashids.py", line 9, in <module>

It looks like it’s coming from here community.general/plugins/filter/hashids.py at main · ansible-collections/community.general · GitHub. I see this isn’t something that’s been adjusted yet in Make ready for data tagging by felixfontein · Pull Request #9833 · ansible-collections/community.general · GitHub - @felixfontein do you want to contain data tagging updates to that PR, or should I open one to update that?

1 Like

@shertel in the PRs I was ignoring deprecations so far, I only looked at things that break and no longer work at all :slight_smile:

I’ve seen some of these AnsibleFilterTypeError messages before, but I’m not yet sure what to do about them - the replacement, AnsibleTypeError, is only available in ansible-core 2.19, but not in other supported ansible-core versions (so we won’t be able to use it for the next ~2 years). So I guess AnsibleFilterError is a better replacement since it works in all ansible-core versions community.general supports.

2 Likes

Could always just do this:

try:
    from ansible.errors import AnsibleTypeError
except ImportError:
    from ansible.errors import AnsibleFilterTypeError as AnsibleTypeError

Or

import ansible.errors
try:
    AnsibleTypeError = ansible.errors.AnsibleTypeError
except AttributeError:
    AnsibleTypeError = ansible.errors.AnsibleFilterTypeError
2 Likes
2 Likes