Repository: langflow-ai/langflow
Pull request: Fixed Lint error and no module error
Fixed https://github.com/logspace-ai/langflow/issues/904
Fixed https://github.com/logspace-ai/langflow/issues/916

/cc @ogabrielluiz

Problem statement:
lint error
```console
% python
Python 3.10.0 (v3.10.0:b494f5935c, Oct  4 2021, 14:59:20) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
```
```console
% make lint
poetry run mypy src/backend/langflow
src/backend/langflow/services/cache/manager.py:13: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/backend/langflow/services/cache/manager.py:35: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/backend/langflow/services/database/models/user/crud.py:58: error: Argument 1 to "update_user" has incompatible type "User | None"; expected "User"  [arg-type]
src/backend/langflow/interface/initialize/loading.py:130: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/backend/langflow/services/chat/manager.py:23: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/backend/langflow/services/chat/manager.py:51: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
src/backend/langflow/api/v1/users.py:97: error: "Session" has no attribute "is_superuser"  [attr-defined]
src/backend/langflow/api/v1/users.py:97: error: "Session" has no attribute "id"  [attr-defined]
src/backend/langflow/api/v1/users.py:122: error: "Session" has no attribute "id"  [attr-defined]
src/backend/langflow/api/v1/users.py:129: error: "Session" has no attribute "password"  [attr-defined]
src/backend/langflow/api/v1/users.py:134: error: "Session" has no attribute "password"  [attr-defined]
src/backend/langflow/api/v1/users.py:138: error: Incompatible return value type (got "Session", expected "User")  [return-value]
src/backend/langflow/api/v1/endpoints.py:45: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Found 7 errors in 2 files (checked 191 source files)
make: *** [lint] Error 1
```

all test failed and langflow cannot start due to "No module named 'langflow.settings'"
```

cls = <class 'langflow.services.plugins.langfuse.LangfuseInstance'>

    @classmethod
    def create(cls):
        logger.debug("Creating Langfuse instance")
>       from langflow.settings import settings
E       ModuleNotFoundError: No module named 'langflow.settings'

../../../../../ycliu/lib/python3.10/site-packages/langflow/services/plugins/langfuse.py:20: ModuleNotFoundError
```

Hints from issue discussion:
@ogabrielluiz ^^

Commit message: Fixed lint error

Patch to review:
diff --git a/src/backend/langflow/api/v1/users.py b/src/backend/langflow/api/v1/users.py
index 4b1b936d4307..e68512e438b6 100644
--- a/src/backend/langflow/api/v1/users.py
+++ b/src/backend/langflow/api/v1/users.py
@@ -88,7 +88,7 @@ def read_all_users(
 def patch_user(
     user_id: UUID,
     user_update: UserUpdate,
-    user: Session = Depends(get_current_active_user),
+    user: User = Depends(get_current_active_user),
     session: Session = Depends(get_session),
 ) -> User:
     """
@@ -113,7 +113,7 @@ def patch_user(
 def reset_password(
     user_id: UUID,
     user_update: UserUpdate,
-    user: Session = Depends(get_current_active_user),
+    user: User = Depends(get_current_active_user),
     session: Session = Depends(get_session),
 ) -> User:
     """
diff --git a/src/backend/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py b/src/backend/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py
index da7c0dd73af1..636eb427e314 100644
--- a/src/backend/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py
+++ b/src/backend/langflow/components/textsplitters/LanguageRecursiveTextSplitter.py
@@ -2,7 +2,6 @@
 from langflow import CustomComponent
 from langchain.text_splitter import Language
 from langchain.schema import Document
-from langflow.utils.util import build_loader_repr_from_documents
 
 
 class LanguageRecursiveTextSplitterComponent(CustomComponent):
@@ -78,5 +77,4 @@ def build(
         )
 
         docs = splitter.split_documents(documents)
-        self.repr_value = build_loader_repr_from_documents(docs)
         return docs
diff --git a/src/backend/langflow/components/textsplitters/RecursiveCharacterTextSplitter.py b/src/backend/langflow/components/textsplitters/RecursiveCharacterTextSplitter.py
index 58b061f2f94f..fd04b064241a 100644
--- a/src/backend/langflow/components/textsplitters/RecursiveCharacterTextSplitter.py
+++ b/src/backend/langflow/components/textsplitters/RecursiveCharacterTextSplitter.py
@@ -74,6 +74,5 @@ def build(
         )
 
         docs = splitter.split_documents(documents)
-        # self.repr_value = build_loader_repr_from_documents(docs)
         self.repr_value = separators
         return docs
diff --git a/src/backend/langflow/services/database/models/user/crud.py b/src/backend/langflow/services/database/models/user/crud.py
index abc79f49fe60..fc17d09be515 100644
--- a/src/backend/langflow/services/database/models/user/crud.py
+++ b/src/backend/langflow/services/database/models/user/crud.py
@@ -19,7 +19,7 @@ def get_user_by_id(db: Session, id: UUID) -> Union[User, None]:
 
 
 def update_user(
-    user_db: User, user: UserUpdate, db: Session = Depends(get_session)
+    user_db: Union[User, None], user: UserUpdate, db: Session = Depends(get_session)
 ) -> User:
     if not user_db:
         raise HTTPException(status_code=404, detail="User not found")
diff --git a/src/backend/langflow/services/plugins/langfuse.py b/src/backend/langflow/services/plugins/langfuse.py
index 98375a549a14..7460f20adc7b 100644
--- a/src/backend/langflow/services/plugins/langfuse.py
+++ b/src/backend/langflow/services/plugins/langfuse.py
@@ -1,3 +1,4 @@
+from langflow.services.utils import get_settings_manager
 from langflow.utils.logger import logger
 
 ### Temporary implementation
@@ -17,14 +18,18 @@ def get(cls):
     @classmethod
     def create(cls):
         logger.debug("Creating Langfuse instance")
-        from langflow.settings import settings
         from langfuse import Langfuse  # type: ignore
 
-        if settings.LANGFUSE_PUBLIC_KEY and settings.LANGFUSE_SECRET_KEY:
+        settings_manager = get_settings_manager()
+
+        if (
+            settings_manager.settings.LANGFUSE_PUBLIC_KEY
+            and settings_manager.settings.LANGFUSE_SECRET_KEY
+        ):
             logger.debug("Langfuse credentials found")
             cls._instance = Langfuse(
-                public_key=settings.LANGFUSE_PUBLIC_KEY,
-                secret_key=settings.LANGFUSE_SECRET_KEY,
+                public_key=settings_manager.settings.LANGFUSE_PUBLIC_KEY,
+                secret_key=settings_manager.settings.LANGFUSE_SECRET_KEY,
             )
         else:
             logger.debug("No Langfuse credentials found")
diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx
index 3374ec8b00a7..d71a18ebb7d0 100644
--- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx
+++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx
@@ -120,17 +120,18 @@ export default function ParameterComponent({
         return (
           <>
             {index === 0 && (
-                <span>
-                  {left ? "Avaliable input components:" : "Avaliable output components:"}
-                </span>
-              )
-            }
+              <span>
+                {left
+                  ? "Avaliable input components:"
+                  : "Avaliable output components:"}
+              </span>
+            )}
             <span
               key={index}
               className={classNames(
                 index > 0 ? "mt-2 flex items-center" : "mt-3 flex items-center"
               )}
-              >
+            >
               <div
                 className="h-5 w-5"
                 style={{
@@ -146,8 +147,7 @@ export default function ParameterComponent({
                 />
               </div>
               <span className="ps-2 text-xs text-foreground">
-                {nodeNames[item.family] ?? "Other"}
-                {" "}
+                {nodeNames[item.family] ?? "Other"}{" "}
                 <span className="text-xs">
                   {" "}
                   {item.type === "" ? "" : " - "}
diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx
index 388020f22602..c762b3a67816 100644
--- a/src/frontend/src/CustomNodes/GenericNode/index.tsx
+++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx
@@ -158,9 +158,16 @@ export default function GenericNode({
           </div>
         </div>
 
-        <div className={"generic-node-desc " + (data.node?.description !== "" ? "py-5" : "pb-5")}>
+        <div
+          className={
+            "generic-node-desc " +
+            (data.node?.description !== "" ? "py-5" : "pb-5")
+          }
+        >
           {data.node?.description !== "" && (
-            <div className="generic-node-desc-text">{data.node?.description}</div>
+            <div className="generic-node-desc-text">
+              {data.node?.description}
+            </div>
           )}
 
           <>


Code review comments:
path: src/backend/langflow/components/textsplitters/RecursiveCharacterTextSplitter.py
text: @user1:
Thanks for the PR, @author!

Why not use this function?


@author:
my bad, just found there is no implementation for this API.

Do you know if the implementation is deleted or just do not have this since the beginning?

@user1:
That function is in `langflow.utils.util.build_loader_repr_from_documents` 

@author:
@user1 I did not find the function at https://github.com/logspace-ai/langflow/blob/dev/src/backend/langflow/utils/util.py , am I missing anything? Thanks

@author:
I think I need to add it back if you can provide the content of this function :)

path: src/backend/langflow/services/database/models/user/crud.py
text: @user1:
Maybe `Optional[User]` would be better in this case?

I think the point of this is mainly that a user might not be found in a function that uses this other function.

@author:
Done