Skip to content

Commit

Permalink
Handle none in PyObjectId (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
samarpan1738 committed Dec 11, 2024
1 parent 28475c0 commit df7d693
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion todo/models/common/pyobjectid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down

0 comments on commit df7d693

Please sign in to comment.