fix(sqlalchemy): fixed deprecated methods for sqlalchemy

This commit is contained in:
RhodeCode Admin 2024-10-22 22:15:46 +02:00
parent 6cf678911a
commit 47a4437420
2 changed files with 9 additions and 8 deletions

View file

@ -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,

View file

@ -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)