Skip to content

Commit 2e78428

Browse files
Tharun PaulTharun Paul
authored andcommitted
Fix NaN in json error
1 parent 870168f commit 2e78428

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/models/variables.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from math import isnan
12
from typing import Any, Dict, List, Optional, Union
23

3-
from pydantic import BaseModel, Field, constr
4+
from pydantic import BaseModel, Field, constr, validator
45

56
from app.core.config import Settings
67

@@ -52,6 +53,12 @@ class VariableProperties(BaseModel):
5253
monotonic: Optional[int]
5354
histogram: Optional[List[Any]]
5455

56+
@validator("*")
57+
def change_nan_to_none(cls, v, field):
58+
if field.outer_type_ is float and isnan(v):
59+
return None
60+
return v
61+
5562

5663
class Variables(BaseModel):
5764
__root__: Dict[VARIABLE_COLUMN_CONSTRAINT, VariableProperties]

0 commit comments

Comments
 (0)