Skip to content

Commit 3b07e3f

Browse files
committed
trying a hacky solution
Signed-off-by: wiseaidev <[email protected]>
1 parent 1efdbdf commit 3b07e3f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

aredis_om/model/model.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1283,16 +1283,18 @@ def __init_subclass__(cls, **kwargs):
12831283
f"HashModels cannot index dataclass fields. Field: {name}"
12841284
)
12851285

1286+
def dict(self) -> Dict[str, Any]:
1287+
# restore none values
1288+
return dict(self)
1289+
12861290
async def save(self, pipeline: Optional[Pipeline] = None) -> "HashModel":
12871291
self.check()
12881292
if pipeline is None:
12891293
db = self.db()
12901294
else:
12911295
db = pipeline
1292-
document = jsonable_encoder(self.dict())
1296+
document = jsonable_encoder({key: val if val else "0" for key, val in self.dict().items()})
12931297
# TODO: Wrap any Redis response errors in a custom exception?
1294-
# store null values as string zero: "0"
1295-
document = {key: val if val else "0" for key, val in document.items()}
12961298
await db.hset(self.key(), mapping=document)
12971299
return self
12981300

0 commit comments

Comments
 (0)