Skip to content

Commit a030174

Browse files
authored
fix: byte size serialization in MemoryInfo (#245)
1 parent b7dde24 commit a030174

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/crawlee/_utils/system.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Annotated
99

1010
import psutil
11-
from pydantic import BaseModel, ConfigDict, Field, PlainValidator
11+
from pydantic import BaseModel, ConfigDict, Field, PlainSerializer, PlainValidator
1212

1313
from crawlee._utils.byte_size import ByteSize
1414

@@ -43,8 +43,15 @@ class MemoryInfo(BaseModel):
4343

4444
model_config = ConfigDict(populate_by_name=True)
4545

46-
total_size: Annotated[ByteSize, PlainValidator(ByteSize.validate), Field(alias='totalSize')]
47-
current_size: Annotated[ByteSize, PlainValidator(ByteSize.validate), Field(alias='currentSize')]
46+
total_size: Annotated[
47+
ByteSize, PlainValidator(ByteSize.validate), PlainSerializer(lambda size: size.bytes), Field(alias='totalSize')
48+
]
49+
current_size: Annotated[
50+
ByteSize,
51+
PlainValidator(ByteSize.validate),
52+
PlainSerializer(lambda size: size.bytes),
53+
Field(alias='currentSize'),
54+
]
4855
created_at: datetime = Field(
4956
alias='createdAt',
5057
default_factory=lambda: datetime.now(timezone.utc),

0 commit comments

Comments
 (0)