question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validator's first agument warning when using @pydantic.validator

See original GitHub issue

Describe the bug PyCharm is not seeing validator function as a class method when using @pydantic.validator instead of @validator

To Reproduce Steps to reproduce the behavior:

  1. Define a pydantic model
  2. Define avalidator function using @pydantic.validator(...) as a decorator instead of using @validator(...)
  3. See error

Expected behavior PyCharm should not warn about using self instead cls since validator() returns class method

Screenshots image

image

Environments (please complete the following information):

  • IDE: PyCharm Professional 2021.1
  • OS: macOS Big Sur
  • Pydantic Version: 1.8.2
  • Plugin version: 0.3.4

Additional context None

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
koxudaxicommented, Aug 8, 2021

That’s good news. I’m happy to resolve your problem.

I don’t close this issue now. If I get the time then I will check the problem deeply.

1reaction
earthpyycommented, Aug 5, 2021

@koxudaxi Hello, I just tried to reproduce and found that the import statement was import pydantic.generics instead of import pydantic. I think because the other place in the same file was using pydantic.generics.Generic.

I also found that it isn’t practical to import like that and using pydantic.validator later. Changing the import statement back to import pydantic works. I’m not sure if there is anything to fix in this case. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validators - pydantic
validators are "class methods", so the first argument value they receive is the UserModel class, not an instance of UserModel . the second...
Read more >
How to Validate Your Data with Custom Validators of Pydantic ...
Since a validator works as a class method, the first argument is the class which is named cls as a convention.
Read more >
pylint complain on models with validators since version 0.27
model.py:12:4: E0213: Method should have "self" as first argument (no-self-argument) ... These complaints does not occur with pydantic 0.26.
Read more >
How we validate input data using pydantic
Pydantic raises a ValidationError when the validation of the model fails, stating which field, i.e. attribute, raised the error and why. In this ......
Read more >
Strict Type Validation With Pydantic - Section.io
Type validation is the process of making sure what you get is what you are expecting. If an endpoint is supposed to get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found