9
9
from enum import StrEnum
10
10
from typing import Literal
11
11
12
- from pydantic import BaseModel , Field
12
+ from pydantic import BaseModel , Field , field_validator
13
13
from typing_extensions import TypedDict
14
14
15
15
@@ -75,7 +75,7 @@ class SearchParams(BaseModel):
75
75
# TODO: Add more validation
76
76
77
77
78
- class JobParameters (BaseModel , extra = "forbid" ):
78
+ class JobParameters (BaseModel ):
79
79
"""All the parameters that can be set for a job."""
80
80
81
81
timestamp : datetime | None = None
@@ -95,8 +95,25 @@ class JobParameters(BaseModel, extra="forbid"):
95
95
job_type : str | None = Field (None , alias = "JobType" )
96
96
job_status : str | None = Field (None , alias = "JobStatus" )
97
97
98
-
99
- class JobAttributes (BaseModel , extra = "forbid" ):
98
+ @field_validator (
99
+ "cpu_normalization_factor" , "norm_cpu_time_s" , "total_cpu_time_s" , mode = "before"
100
+ )
101
+ @classmethod
102
+ def convert_cpu_fields_to_int (cls , v ):
103
+ """Convert string representation of float to integer for CPU-related fields."""
104
+ if v is None :
105
+ return v
106
+ if isinstance (v , str ):
107
+ try :
108
+ return int (float (v ))
109
+ except (ValueError , TypeError ) as e :
110
+ raise ValueError (f"Cannot convert '{ v } ' to integer" ) from e
111
+ if isinstance (v , (int , float )):
112
+ return int (v )
113
+ return v
114
+
115
+
116
+ class JobAttributes (BaseModel ):
100
117
"""All the attributes that can be set for a job."""
101
118
102
119
job_type : str | None = Field (None , alias = "JobType" )
@@ -121,7 +138,7 @@ class JobAttributes(BaseModel, extra="forbid"):
121
138
accounted_flag : bool | str | None = Field (None , alias = "AccountedFlag" )
122
139
123
140
124
- class JobMetaData (JobAttributes , JobParameters , extra = "forbid" ):
141
+ class JobMetaData (JobAttributes , JobParameters ):
125
142
"""A model that combines both JobAttributes and JobParameters."""
126
143
127
144
0 commit comments