-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Initial Checks
- I confirm that I'm using Pydantic V2
Description
while trying to find a work around on #7574
I find another potentially unexpected behavior of computed field, that:
within a same class, if an attribute is rewritten using computed field, that attribute isn't needed for instantiation of the class.
Example Code
The following code won't raise any error
from pydantic import BaseModel, computed_field
class Event(BaseModel):
event_id:str
@computed_field
def event_id(self) -> str:
return "random"
e = Event()
assert isinstance(e.event_id, property)
The following code would raise Attribute Error
from dataclasses import dataclass
@dataclass
class T:
name:str
@property
def name(self):
return "name"
T()
AttributeError: property 'name' of 'T' object has no setter
### Python, Pydantic & OS Version
```Text
python version: sys.version_info(major=3, minor=10, micro=13, releaselevel='final', serial=0)
pydantic version: 2.3.0
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
pydantic version: 2.3.0
pydantic-core version: 2.6.3
pydantic-core build: profile=release pgo=true
install path: /home/raceychan/miniconda3/envs/askgpt/lib/python3.10/site-packages/pydantic
python version: 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0]
platform: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
optional deps. installed: ['typing-extensions']
Metadata
Metadata
Assignees
Labels
bug V2Bug related to Pydantic V2Bug related to Pydantic V2