Skip to content

Commit 0e3e4c9

Browse files
committed
Use bson.ObjectID for user management rather than int (from SQLAlchemy)
1 parent f94ff17 commit 0e3e4c9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
def try_int(text) -> int:
1+
from typing import Optional
2+
3+
4+
def try_int(text) -> Optional[int]:
25
try:
36
return int(text)
47
except:
5-
return 0
8+
return None

app/ch16_mongodb/final/pypi_org/services/user_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Optional
22

3+
import bson
34
from passlib.handlers.sha2_crypt import sha512_crypt as crypto
45
from pypi_org.nosql.users import User
56

@@ -46,6 +47,6 @@ def login_user(email: str, password: str) -> Optional[User]:
4647
return user
4748

4849

49-
def find_user_by_id(user_id: int) -> Optional[User]:
50+
def find_user_by_id(user_id: bson.ObjectId) -> Optional[User]:
5051
user = User.objects().filter(id=user_id).first()
5152
return user

0 commit comments

Comments
 (0)