Skip to content

Commit

Permalink
Use sqlalchemy.select instead of sqlmodel.select
Browse files Browse the repository at this point in the history
It seems to work the same but the sqlmodel version resulted in a mypy
false alert in local_auth.py.
Further, let's avoid using an additional package if it's not needed.
  • Loading branch information
luator committed Jan 14, 2025
1 parent 2ebec16 commit 754f559
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
8 changes: 3 additions & 5 deletions comprl-web-reflex/comprl_web/reflex_local_auth/local_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import datetime

from sqlmodel import select

import sqlalchemy as sa
import reflex as rx

Expand Down Expand Up @@ -38,15 +36,15 @@ class LocalAuthState(rx.State):

@rx.var(cache=True)
def authenticated_user(self) -> User | None:
"""The currently authenticated user, or a dummy user if not authenticated.
"""The currently authenticated user.
Returns:
User instance corresponding to the currently authenticated user or None if
no user is authenticated.
"""
with get_session() as session:
result = session.scalars(
select(User, LocalAuthSession).where(
sa.select(User, LocalAuthSession).where(
LocalAuthSession.session_id == self.auth_token,
LocalAuthSession.expiration
>= datetime.datetime.now(datetime.timezone.utc),
Expand All @@ -70,7 +68,7 @@ def do_logout(self) -> None:
"""Destroy LocalAuthSessions associated with the auth_token."""
with get_session() as session:
for auth_session in session.scalars(
select(LocalAuthSession).where(
sa.select(LocalAuthSession).where(
LocalAuthSession.session_id == self.auth_token
)
).all():
Expand Down
6 changes: 1 addition & 5 deletions comprl-web-reflex/comprl_web/reflex_local_auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import bcrypt
import reflex as rx
from sqlmodel import select
from sqlalchemy import select

from comprl.server.data.sql_backend import User

Expand Down Expand Up @@ -44,10 +44,6 @@ def on_submit(self, form_data) -> rx.event.EventSpec:
self.error_message = ""
username = form_data["username"]
password = form_data["password"]
# with rx.session() as session:
# user = session.exec(
# select(User).where(User.username == username)
# ).one_or_none()

with get_session() as session:
user = session.scalars(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import reflex as rx

from sqlmodel import select
from sqlalchemy import select

from comprl.server.util import IDGenerator
from comprl.server.data.sql_backend import User, hash_password
Expand Down

0 comments on commit 754f559

Please sign in to comment.