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

Attempting to use a non-existing model field is not detected as a problem in pydantic v2 #851

Closed
oleg-rmd opened this issue Dec 19, 2023 · 1 comment · Fixed by #858
Closed
Labels
bug Something isn't working

Comments

@oleg-rmd
Copy link

oleg-rmd commented Dec 19, 2023

Describe the bug
Attempting to use a non-existing field does not get marked as a warning when using pydantic v2.

To Reproduce

  1. Ensure "Python | Type checker compatible with Pydantic", "Python | Pydantic definition and usages", and "Python | Unresolved references" inspections are configured to level warning.
  • NOTE: I also tried disabling them one at a time, and it did not make a difference.
  • NOTE: There is no such inspection "Type Checker" any more, so I cannot disable it.
  1. Create a python file with the following code.
import dataclasses

from pydantic import BaseModel


@dataclasses.dataclass
class A:
    a: int = 1


class B(BaseModel):
    a: int = 1


a = A(a=1)
print(a.fake)

b = B(a=1)
print(b.fake)

Actual behavior
a.fake generates an unresolved reference warning, but b.fake does not show any warning.

Expected behavior
b.fake should be flagged as unresolved reference, non-existing attribute, or similar warning.

Screenshots
image

Environments (please complete the following information):

  • IDE: PyCharm 2023.3.1 (Professional Edition)
  • OS: macOS 12.7.1
  • Pydantic Version 2.5.2
  • Python Version 3.12.1 (also tried with 3.9.x)
  • Plugin version 0.4.10

Additional context

Also reproduced on CLion Nova with the Python Community Edition plugin 233.13309

I also tried:

  • Uninstalling and re-installing pydantic
  • "Repair IDE" (all the way to Invalidate Caches and Restart)

Switching the import to from pydantic.v1 import BaseModel fixes the issue.

@oleg-rmd oleg-rmd changed the title Attempting to use a non-existing model field is not detected as a problem. Attempting to use a non-existing model field is not detected as a problem in pydantic v2 Dec 19, 2023
@koxudaxi koxudaxi added the bug Something isn't working label Dec 24, 2023
@koxudaxi
Copy link
Owner

koxudaxi commented Dec 24, 2023

@oleg-rmd
Thank you for creating the issue
I agree with you.
I will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants