Skip to content

validate_arguments allows overriding positional argument with kwarg #2249

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

Closed
3 tasks done
antdking opened this issue Jan 10, 2021 · 0 comments · Fixed by #2250
Closed
3 tasks done

validate_arguments allows overriding positional argument with kwarg #2249

antdking opened this issue Jan 10, 2021 · 0 comments · Fixed by #2250
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@antdking
Copy link
Contributor

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: True
                 install path: /home/anthony/.local/share/virtualenvs/project-4BYEWHa2/lib/python3.8/site-packages/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: ['typing-extensions']
from pydantic import validate_arguments


@validate_arguments
def foo(x: int):
    print(x)


def bar(x: int):
    print(x)

>>> foo(1)
1
>>> foo(1, x=2)
2

>>> bar(1)
1
>>> bar(1, x=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bar() got multiple values for argument 'x'

Currently, validate_arguments does not behave the same as a native function when passing in kwargs that override a positional argument.

expectation is that foo(1, x=2) would raise a ValidationError or TypeError

@antdking antdking added the bug V1 Bug related to Pydantic V1.X label Jan 10, 2021
antdking added a commit to antdking/pydantic that referenced this issue Jan 10, 2021
Currently, it is possible to override a positional argument with a keyword
argument using the decorator.

In native python, this raises a TypeError.

Detect this usecase, to prevent keywords overriding positional parameters.

Closes: pydantic#2249
samuelcolvin added a commit that referenced this issue Feb 13, 2021
* fix(decorator): detect when a duplicate argument is passed in

Currently, it is possible to override a positional argument with a keyword
argument using the decorator.

In native python, this raises a TypeError.

Detect this usecase, to prevent keywords overriding positional parameters.

Closes: #2249

* add changelog entry

* fix docs example to not override positional argument

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
tomasz-kaminski-jir pushed a commit to tomasz-kaminski-jir/pyd_analyze that referenced this issue Mar 23, 2025
* fix(decorator): detect when a duplicate argument is passed in

Currently, it is possible to override a positional argument with a keyword
argument using the decorator.

In native python, this raises a TypeError.

Detect this usecase, to prevent keywords overriding positional parameters.

Closes: pydantic/pydantic#2249

* add changelog entry

* fix docs example to not override positional argument

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant