Skip to content

validate_arguments does not assign **kwargs correctly #2251

@antdking

Description

@antdking

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.7.3
            pydantic compiled: False
                 install path: /home/anthony/experiments/pydantic/pydantic
               python version: 3.8.5 (default, Aug 23 2020, 18:40:40)  [GCC 10.1.0]
                     platform: Linux-5.10.2-2-MANJARO-x86_64-with-glibc2.29
     optional deps. installed: ['devtools', 'dotenv', 'email-validator', 'typing-extensions']
from pydantic import validate_arguments

@validate_arguments
def foo(**kwargs):
    print(f"{kwargs=}")


def bar(**kwargs):
    print(f"{kwargs=}")

>>> foo(kwargs=1, b=2)
kwargs={'b': 2}
>>> bar(kwargs=1, b=2)
kwargs={'kwargs': 1, 'b': 2}

Kwargs doesn't get assigned as per native python implementation.

It looks like the field gets overwritten, as we're checking all input kwargs against all fields, including the special var_kwarg field.
https://github.com/samuelcolvin/pydantic/blob/8bad7bc91105616dfcc23ce1d68fba12f328a2a3/pydantic/decorator.py#L166

Should be as simple as set(self.model.__fields__) - {self.v_kwargs_name} to resolve, will prepare a patch now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions