mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(fastapi): support UsersID and User columns in the Session model
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
31a093ba06
commit
a0e1a1641d
1 changed files with 10 additions and 4 deletions
|
@ -18,10 +18,16 @@ class Session(Base):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
user_exists = db.query(
|
# We'll try to either use UsersID or User.ID if we can.
|
||||||
db.query(_User).filter(_User.ID == self.UsersID).exists()
|
# If neither exist, an AttributeError is raised, in which case
|
||||||
).scalar()
|
# we set the uid to 0, which triggers IntegrityError below.
|
||||||
if not user_exists:
|
try:
|
||||||
|
uid = self.UsersID or self.User.ID
|
||||||
|
except AttributeError:
|
||||||
|
uid = 0
|
||||||
|
|
||||||
|
user_exists = db.query(_User).filter(_User.ID == uid).exists()
|
||||||
|
if not db.query(user_exists).scalar():
|
||||||
raise IntegrityError(
|
raise IntegrityError(
|
||||||
statement=("Foreign key UsersID cannot be null and "
|
statement=("Foreign key UsersID cannot be null and "
|
||||||
"must be a valid user's ID."),
|
"must be a valid user's ID."),
|
||||||
|
|
Loading…
Add table
Reference in a new issue