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

validate_arguments on the simplest func raise a NameError attributes shadowing, is this expected? #1894

Closed
WestXu opened this issue Sep 2, 2020 · 5 comments
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@WestXu
Copy link

WestXu commented Sep 2, 2020

from pydantic import validate_arguments

@validate_arguments
def query(x: int, fields):
    pass

Run as-is, got a NameError: Field name "fields" shadows a BaseModel attribute; use a different field name with "alias='fields'".

Is this expected? Cause fields is a most frequently-used arg name. Noticed #1250, but validate_arguments even without type annotations (like def query(fields)) raises this error. I mean, not ideal. Any easy workaround on this one?

Cool project though.

@WestXu WestXu added the bug V1 Bug related to Pydantic V1.X label Sep 2, 2020
@PrettyWood
Copy link
Member

Hello @WestXu
Unfortunately yes it's "normal" as it creates behind the scene a BaseModel
Feedback welcome on #1205

@ezwelty
Copy link

ezwelty commented Dec 10, 2020

Could this be addressed by internally using aliases for fields with colliding field names, then returning the validated values by their (original) alias names?

@zhqu1148980644
Copy link

same, any solutions?

@PrettyWood
Copy link
Member

PrettyWood commented Apr 25, 2021

It should have been fixed in v1.8 by #2415. @zhqu1148980644 which version are you using? If this is v1.8 please share a code snippet to reproduce.

@zhqu1148980644
Copy link

@PrettyWood Thanks, it's v1.73, I'll try the newest version.

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

No branches or pull requests

4 participants