Skip to content

Commit d28d9da

Browse files
committed
Fixed error when user doesn't have birthdate
1 parent b905810 commit d28d9da

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

backend/PyMatcha/models/user.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,13 @@ def to_dict(self) -> Dict:
193193
returned_dict.pop("password")
194194
returned_dict.pop("previous_reset_token")
195195

196-
today = datetime.datetime.utcnow()
197-
returned_dict["age"] = (
198-
today.year - self.birthdate.year - ((today.month, today.day) < (self.birthdate.month, self.birthdate.day))
199-
)
196+
if self.birthdate:
197+
today = datetime.datetime.utcnow()
198+
returned_dict["age"] = (
199+
today.year
200+
- self.birthdate.year
201+
- ((today.month, today.day) < (self.birthdate.month, self.birthdate.day))
202+
)
200203
return returned_dict
201204

202205
@classmethod

0 commit comments

Comments
 (0)