{"id":1006,"hash":"e8e118ada754be86cf510bc2ba74c8bbe72496381d1ce88b3e713175d83a983b","pattern":"Why do I get &quot;AttributeError: __fields_set__&quot; when subclassing a Pydantic BaseModel?","full_message":"I have this project where my base class and my sub-classes implement pydantic.BaseModel:\n\nfrom pydantic import BaseModel\nfrom typing import List\nfrom dataclasses import dataclass\n\n@dataclass\nclass User(BaseModel):\n    id: int \n\n@dataclass\nclass FavoriteCar(User):\n    car_names: List[str] \n\ncar = FavoriteCar(id=1, car_names=[\"Acura\"])\nprint(f\"{car.id} {car.car_names[0]}\")\n\nBut this error appears:\n\n    self.__fields_set__.add(name)\nE   AttributeError: __fields_set__\n\nDoes someone mind explaining what is going on? The reason why I want to use pydantic is because I need a way to quickly convert Python objects to dict (or JSON) and back.","ecosystem":"pypi","package_name":"pydantic","package_version":null,"solution":"You need to decide whether to inherit from pydantic.BaseModel, or whether to use the @dataclass decorator (either from dataclasses, or from pydantic.dataclasses).\n\nEither is fine, but you cannot use both, according to the documentation (bold face added by myself):\n\n  If you don't want to use pydantic's BaseModel you can instead get the same data validation on standard dataclasses","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/60158357/why-do-i-get-attributeerror-fields-set-when-subclassing-a-pydantic-basemo","votes":43,"created_at":"2026-04-19T04:52:10.773055+00:00","updated_at":"2026-04-19T04:52:10.773055+00:00"}