import dataclasses
@dataclasses.dataclass
class FlexibilityResult:
lengths: list[float]
breadths: list[float]
heights: list[float]
volumes: list[float] = dataclasses.field(default_factory=lambda: [])
def __post_init__(self):
for length, breadth, height in zip(
self.lengths, self.breadths, self.heights
):
self.volumes.append(length*breadth*height)
This is running as expected when I run the method locally, but when a Rest GET API hits and the params are passed, the response has the post_init method executed Twice.
When I hit the API with params as (1,2,3), (1,2,3), (1,2,3) as lengths, breadths, heights respectively, the response should have volumes = (1,8,27) in the dataclass, but it gives (1,8,27,1,8,27) For some reason the post_init runs twice.