File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed
Expand file tree Collapse file tree 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":
13161316 if not document :
13171317 raise NotFoundError
13181318 try :
1319+ # restore none values
1320+ document = {key : val if val != "0" else None for key , val in document .items ()}
13191321 result = cls .parse_obj (document )
13201322 except TypeError as e :
13211323 log .warning (
@@ -1332,14 +1334,14 @@ async def get(cls, pk: Any) -> "HashModel":
13321334 @no_type_check
13331335 def _get_value (cls , * args , ** kwargs ) -> Any :
13341336 """
1335- Always send None as an empty string.
1337+ Always send None as a zero string: "0" to handle Optional int and float fields .
13361338
13371339 TODO: We do this because redis-py's hset() method requires non-null
13381340 values. Is there a better way?
13391341 """
13401342 val = super ()._get_value (* args , ** kwargs )
13411343 if val is None :
1342- return ""
1344+ return "0 "
13431345 return val
13441346
13451347 @classmethod
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ class Member(BaseHashModel):
4848 last_name : str = Field (index = True )
4949 email : str = Field (index = True )
5050 join_date : datetime .date
51+ height : Optional [int ] = None
52+ weight : Optional [float ] = None
5153 age : int = Field (index = True , sortable = True )
5254 bio : str = Field (index = True , full_text_search = True )
5355
You can’t perform that action at this time.
0 commit comments