saltstack / saltstack/salt

[Bug]: `namespaced_function`/`alias_function` drop kwdefaults

Open Beginner friendly
#69,901 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

What happened?

Having used salt.utils.functools.namespaced_function (or alias_function) to copy a function that has keyword-only arguments with defaults and calling the copy without providing a value for these yields a TypeError. Example:

from salt.utils.functools import namespaced_function, alias_function

def foo(bar=None, *_, baz=None):
    pass

foo_ns = namespaced_function(foo, globals())
foo_alias = alias_function(foo, "foo_alias")

foo()
foo_ns()
# Traceback (most recent call last):
#   File "<python-input-13>", line 1, in <module>
#     foo_ns()
#     ~~~~~~^^
# TypeError: foo() missing 1 required keyword-only argument: 'baz'
foo_alias()
# Traceback (most recent call last):
#   File "<python-input-14>", line 1, in <module>
#     foo_ns()
#     ~~~~~~^^
# TypeError: foo() missing 1 required keyword-only argument: 'baz'
Type of salt install

Official deb

Major version

3006.x

What supported OS are you seeing the problem on? Can select multiple. (If bug appears on an unsupported OS, please open a GitHub Discussion instead)

ubuntu-24.04

salt --versions-report output
Current HEAD of 3006.x

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading salt.utils.functools.namespaced_function and alias_function, then reproduce the reported calls with a keyword-only default such as baz=None. Done means both copied functions retain the original keyword defaults and the regression tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.