From f060155fe604efaa0118c11cc18b5bea712ffc14 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 20 Oct 2023 18:25:42 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(utils.py):=20refactor=20se?= =?UTF-8?q?tup=5Fsuperuser=20and=20teardown=5Fsuperuser=20functions=20to?= =?UTF-8?q?=20improve=20readability=20and=20remove=20unnecessary=20code=20?= =?UTF-8?q?duplication=20=F0=9F=94=A7=20chore(utils.py):=20update=20teardo?= =?UTF-8?q?wn=5Fsuperuser=20function=20to=20only=20remove=20default=20supe?= =?UTF-8?q?ruser=20if=20AUTO=5FLOGIN=20is=20set=20to=20False?= 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, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/services/utils.py b/src/backend/langflow/services/utils.py index 96c89a707..c5976ef61 100644 --- a/src/backend/langflow/services/utils.py +++ b/src/backend/langflow/services/utils.py @@ -102,6 +102,9 @@ def get_or_create_super_user(session: Session, username, password, is_default): 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.") + else: + # Remove the default superuser if it exists + teardown_superuser(settings_service, session) username = settings_service.auth_settings.SUPERUSER password = settings_service.auth_settings.SUPERUSER_PASSWORD @@ -132,10 +135,12 @@ def teardown_superuser(settings_service, session): # If AUTO_LOGIN is True, we will remove the default superuser # from the database. - if settings_service.auth_settings.AUTO_LOGIN: + if not settings_service.auth_settings.AUTO_LOGIN: try: - logger.debug("AUTO_LOGIN is set to True. Removing default superuser.") - username = settings_service.auth_settings.SUPERUSER + logger.debug( + "AUTO_LOGIN is set to False. Removing default superuser if exists." + ) + username = DEFAULT_SUPERUSER from langflow.services.database.models.user.user import User user = session.query(User).filter(User.username == username).first()