-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
pytest returtn "AttributeError: 'Person' object has no attribute '__pydantic_extra__'" in V2 #7556
Comments
I'm not sure about you set up but you are not calling super init --- If you want to set attributes ( def __init__(self, x, y):
super().__init__()
self._x = x
self._y = y
|
tried, still same error message |
Take a look at your patch def test_result():
person = Person(x = 3, y = 4)
assert person.do_work() == 7 |
Because the original code , the test case was writting this way... , instead of this
the original code in that part is like this:
Sorry I cannot show the full code for the original part due to some policy in there.. |
Got it, the problem is that you are not patching the init properly |
|
Your problem is that by patching If you really want to do something like this, you can set them manually like this: def newinit(self, x, y):
object.__setattr__(self, '__pydantic_extra__', {})
object.__setattr__(self, '__pydantic_private__', {})
object.__setattr__(self, '__pydantic_fields_set__', set())
self._x = x
self._y = y But (while not knowing anything about what you're trying to achieve), I suspect what you're doing in conceptually wrong. |
Initial Checks
Description
Behavior for below test case is different, in v1 it run it successfully and pass, but in the v2 I got following:
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: