File tree 2 files changed +6
-2
lines changed
2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -1316,6 +1316,8 @@ async def get(cls, pk: Any) -> "HashModel":
1316
1316
if not document :
1317
1317
raise NotFoundError
1318
1318
try :
1319
+ # restore none values
1320
+ document = {key : val if val != "0" else None for key , val in document .items ()}
1319
1321
result = cls .parse_obj (document )
1320
1322
except TypeError as e :
1321
1323
log .warning (
@@ -1332,14 +1334,14 @@ async def get(cls, pk: Any) -> "HashModel":
1332
1334
@no_type_check
1333
1335
def _get_value (cls , * args , ** kwargs ) -> Any :
1334
1336
"""
1335
- Always send None as an empty string.
1337
+ Always send None as a zero string: "0" to handle Optional int and float fields .
1336
1338
1337
1339
TODO: We do this because redis-py's hset() method requires non-null
1338
1340
values. Is there a better way?
1339
1341
"""
1340
1342
val = super ()._get_value (* args , ** kwargs )
1341
1343
if val is None :
1342
- return ""
1344
+ return "0 "
1343
1345
return val
1344
1346
1345
1347
@classmethod
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ class Member(BaseHashModel):
48
48
last_name : str = Field (index = True )
49
49
email : str = Field (index = True )
50
50
join_date : datetime .date
51
+ height : Optional [int ] = None
52
+ weight : Optional [float ] = None
51
53
age : int = Field (index = True , sortable = True )
52
54
bio : str = Field (index = True , full_text_search = True )
53
55
You can’t perform that action at this time.
0 commit comments