From 7390c91028994c6964afc123a2539bc7e9fd093b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 3 Oct 2023 14:27:12 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(utils.py):=20add=20type=20?= =?UTF-8?q?hinting=20to=20the=20get=5For=5Fcreate=5Fsuper=5Fuser=20functio?= =?UTF-8?q?n=20to=20improve=20code=20readability=20and=20maintainability?= =?UTF-8?q?=20=F0=9F=94=A7=20chore(utils.py):=20add=20type=20hinting=20to?= =?UTF-8?q?=20the=20session=20parameter=20in=20the=20get=5For=5Fcreate=5Fs?= =?UTF-8?q?uper=5Fuser=20function=20to=20improve=20code=20readability=20an?= =?UTF-8?q?d=20maintainability=20=F0=9F=94=A7=20chore(utils.py):=20add=20t?= =?UTF-8?q?ype=20hinting=20to=20the=20session=20parameter=20in=20the=20set?= =?UTF-8?q?up=5Fsuperuser=20function=20to=20improve=20code=20readability?= =?UTF-8?q?=20and=20maintainability=20=F0=9F=94=A7=20chore(utils.py):=20ad?= =?UTF-8?q?d=20type=20hinting=20to=20the=20session=20parameter=20in=20the?= =?UTF-8?q?=20setup=5Fsuperuser=20function=20to=20improve=20code=20readabi?= =?UTF-8?q?lity=20and=20maintainability=20=F0=9F=94=A7=20chore(utils.py):?= =?UTF-8?q?=20add=20type=20hinting=20to=20the=20session=20parameter=20in?= =?UTF-8?q?=20the=20setup=5Fsuperuser=20function=20to=20improve=20code=20r?= =?UTF-8?q?eadability=20and=20maintainability=20=F0=9F=94=A7=20chore(utils?= =?UTF-8?q?.py):=20add=20type=20hinting=20to=20the=20session=20parameter?= =?UTF-8?q?=20in=20the=20setup=5Fsuperuser=20function=20to=20improve=20cod?= =?UTF-8?q?e=20readability=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/services/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/services/utils.py b/src/backend/langflow/services/utils.py index 6a6696faf..20c23f8c0 100644 --- a/src/backend/langflow/services/utils.py +++ b/src/backend/langflow/services/utils.py @@ -6,11 +6,12 @@ from langflow.services.settings.constants import ( DEFAULT_SUPERUSER, DEFAULT_SUPERUSER_PASSWORD, ) +from sqlmodel import Session from .getters import get_session, get_settings_service from loguru import logger -def get_or_create_super_user(session, username, password, is_default): +def get_or_create_super_user(session: Session, username, password, is_default): from langflow.services.database.models.user.user import User user = session.query(User).filter(User.username == username).first() @@ -54,10 +55,10 @@ def get_or_create_super_user(session, username, password, is_default): else: logger.debug("Creating superuser.") - return create_super_user(session, username, password) + return create_super_user(username, password, db=session) -def setup_superuser(settings_service, session): +def setup_superuser(settings_service, session: Session): if settings_service.auth_settings.AUTO_LOGIN: logger.debug("AUTO_LOGIN is set to True. Creating default superuser.") @@ -69,7 +70,9 @@ def setup_superuser(settings_service, session): ) try: - user = get_or_create_super_user(session, username, password, is_default) + user = get_or_create_super_user( + session=session, username=username, password=password, is_default=is_default + ) if user is not None: logger.debug("Superuser created successfully.") except Exception as exc: