3939from langflow .services .database .models .flow .model import Flow , FlowCreate
4040from langflow .services .database .models .folder .constants import DEFAULT_FOLDER_NAME
4141from langflow .services .database .models .folder .model import Folder , FolderCreate , FolderRead
42- from langflow .services .database .models .user .crud import get_user_by_username
4342from langflow .services .deps import get_settings_service , get_storage_service , get_variable_service , session_scope
4443
4544# In the folder ./starter_projects we have a few JSON files that represent
@@ -727,20 +726,21 @@ async def load_flows_from_directory() -> None:
727726 """On langflow startup, this loads all flows from the directory specified in the settings.
728727
729728 All flows are uploaded into the default folder for the superuser.
730- Note that this feature currently only works if AUTO_LOGIN is enabled in the settings.
731729 """
732730 settings_service = get_settings_service ()
733731 flows_path = settings_service .settings .load_flows_path
734732 if not flows_path :
735733 return
736- if not settings_service .auth_settings .AUTO_LOGIN :
737- await logger .awarning ("AUTO_LOGIN is disabled, not loading flows from directory" )
738- return
739734
740735 async with session_scope () as session :
741- user = await get_user_by_username (session , settings_service .auth_settings .SUPERUSER )
736+ # Find superuser by role instead of username to avoid issues with credential reset
737+ from langflow .services .database .models .user .model import User
738+
739+ stmt = select (User ).where (User .is_superuser == True ) # noqa: E712
740+ result = await session .exec (stmt )
741+ user = result .first ()
742742 if user is None :
743- msg = "Superuser not found in the database"
743+ msg = "No superuser found in the database"
744744 raise NoResultFound (msg )
745745
746746 # Ensure that the default folder exists for this user
@@ -793,13 +793,16 @@ async def load_bundles_from_urls() -> tuple[list[TemporaryDirectory], list[str]]
793793 bundle_urls = settings_service .settings .bundle_urls
794794 if not bundle_urls :
795795 return [], []
796- if not settings_service .auth_settings .AUTO_LOGIN :
797- await logger .awarning ("AUTO_LOGIN is disabled, not loading flows from URLs" )
798796
799797 async with session_scope () as session :
800- user = await get_user_by_username (session , settings_service .auth_settings .SUPERUSER )
798+ # Find superuser by role instead of username to avoid issues with credential reset
799+ from langflow .services .database .models .user .model import User
800+
801+ stmt = select (User ).where (User .is_superuser == True ) # noqa: E712
802+ result = await session .exec (stmt )
803+ user = result .first ()
801804 if user is None :
802- msg = "Superuser not found in the database"
805+ msg = "No superuser found in the database"
803806 raise NoResultFound (msg )
804807 user_id = user .id
805808
@@ -816,11 +819,7 @@ async def load_bundles_from_urls() -> tuple[list[TemporaryDirectory], list[str]]
816819 for filename in zfile .namelist ():
817820 path = Path (filename )
818821 for dir_name in dir_names :
819- if (
820- settings_service .auth_settings .AUTO_LOGIN
821- and path .is_relative_to (f"{ dir_name } flows/" )
822- and path .suffix == ".json"
823- ):
822+ if path .is_relative_to (f"{ dir_name } flows/" ) and path .suffix == ".json" :
824823 file_content = zfile .read (filename )
825824 await upsert_flow_from_file (file_content , path .stem , session , user_id )
826825 elif path .is_relative_to (f"{ dir_name } components/" ):
0 commit comments