Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] getfullargspec and annotations #61981

Open
nagylzs opened this issue Apr 24, 2022 · 1 comment
Open

[BUG] getfullargspec and annotations #61981

nagylzs opened this issue Apr 24, 2022 · 1 comment
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt severity-low 4th level, cosemtic problems, work around exists
Milestone

Comments

@nagylzs
Copy link

nagylzs commented Apr 24, 2022

Description

I think this issue is very similar to #48735 - in some cases, salt throws this annoying error:

ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them

Setup

I have tried to create a custom state, and used this function signature:

def cluster(
        name: str,
        config,
        initial_primary_node: str,
        base_dir=None,
        bind_mounts=None,
        image=None
):
    pass # return state result here...

The problem seems to be that the function is partially annotated. If I remove all annotations, like this:

def cluster(
        name,
        config,
        initial_primary_node,
        base_dir=None,
        bind_mounts=None,
        image=None
):
    pass # return state result here...

Then it works.

Steps to Reproduce the behavior

Install the 3004.1 and try to create a custom state under file_root/_states/test.py with the above signature, and then try to apply that state on a minion.

Full debug log when calling state.apply:

    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/salt/minion.py", line 1912, in _thread_return
        return_data = minion_instance._execute_job_function(
      File "/usr/lib/python3/dist-packages/salt/minion.py", line 1869, in _execute_job_function
        return_data = self.executors[fname](opts, data, func, args, kwargs)
      File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1201, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1216, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/executors/direct_call.py", line 10, in execute
        return func(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1201, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1216, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/modules/state.py", line 793, in apply_
        return sls(mods, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/modules/state.py", line 1392, in sls
        ret = st_.state.call_high(high_, orchestration_jid)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 3279, in call_high
        ret = self.call_chunks(chunks)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 2497, in call_chunks
        running = self.call_chunk(low, running, chunks)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 3003, in call_chunk
        running[tag] = self.call(low, chunks, running)
      File "/usr/lib/python3/dist-packages/salt/utils/decorators/state.py", line 45, in _func
        result = func(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 2067, in call
        errors = self.verify_data(low)
      File "/usr/lib/python3/dist-packages/salt/state.py", line 1309, in verify_data
        aspec = salt.utils.args.get_function_argspec(self.states[full])
      File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 269, in get_function_argspec
        aspec = _getargspec(func)
      File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 37, in _getargspec
        raise ValueError(
    ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
ERROR: Minions returned with non-zero exit code

Expected behavior

It should not throw errors for annotated functions.

Versions Report

Salt Version:
Salt: 3004.1

Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: 3.6.1
pygit2: Not Installed
Python: 3.8.10 (default, Mar 15 2022, 12:22:08)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 18.1.1
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2

System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-107-generic
system: Linux
version: Ubuntu 20.04 focal

All masters and minions have the same versions.

@nagylzs nagylzs added Bug broken, incorrect, or confusing behavior needs-triage labels Apr 24, 2022
@welcome
Copy link

welcome bot commented Apr 24, 2022

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@OrangeDog OrangeDog added severity-low 4th level, cosemtic problems, work around exists Core relates to code central or existential to Salt and removed needs-triage labels Apr 25, 2022
@OrangeDog OrangeDog added this to the Approved milestone Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

No branches or pull requests

2 participants