From 1d374f38dda0555b1a1679c4c8315378ecfa71f5 Mon Sep 17 00:00:00 2001 From: Samarpan Harit Date: Sat, 7 Dec 2024 23:59:11 +0530 Subject: [PATCH] Handle none in PyObjectId (#5) --- todo/models/common/pyobjectid.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/todo/models/common/pyobjectid.py b/todo/models/common/pyobjectid.py index eb42f74..935e0ab 100644 --- a/todo/models/common/pyobjectid.py +++ b/todo/models/common/pyobjectid.py @@ -8,7 +8,9 @@ def __get_validators__(cls): @classmethod def validate(cls, value, field=None): - if value is None or ObjectId.is_valid(value): + if value is None: + return None + if value is not None and ObjectId.is_valid(value): return ObjectId(value) raise ValueError(f"Invalid ObjectId: {value}")