diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -284,7 +284,7 @@ class BaseModel(object): @classmethod def get(cls, id_): if id_: - return cls.query().get(id_) + return Session().get(cls, id_) @classmethod def get_or_404(cls, id_): @@ -1077,11 +1077,11 @@ class User(Base, BaseModel): if not user_id: return - user = cls.query() + q = cls.select().where(cls.user_id == user_id) if cache: - user = user.options( + q = q.options( FromCache("sql_cache_short", f"get_users_{user_id}")) - return user.get(user_id) + return cls.execute(q).scalar_one_or_none() @classmethod def get_by_username(cls, username, case_insensitive=False, diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py --- a/rhodecode/model/user.py +++ b/rhodecode/model/user.py @@ -54,11 +54,12 @@ class UserModel(BaseModel): cls = User def get(self, user_id, cache=False): - user = self.sa.query(User) + cls = self.cls + q = cls.select().where(cls.user_id == user_id) if cache: - user = user.options( - FromCache("sql_cache_short", f"get_user_{user_id}")) - return user.get(user_id) + q = q.options( + FromCache("sql_cache_short", f"get_users_{user_id}")) + return cls.execute(q).scalar_one_or_none() def get_user(self, user): return self._get_user(user)