Skip to content

Commit

Permalink
fix: raise ImportError instead of silencing AttributeError (langflow-…
Browse files Browse the repository at this point in the history
…ai#4812)

* fix: raise ImportError instead of silencing AttributeError

* chore: add Message class to init for import standardization

* feat: add exception message pattern check for import errors

* refactor: simplify code
  • Loading branch information
italojohnny authored and diogocabral committed Nov 26, 2024
1 parent 329fd60 commit 87bf220
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import operator
import re
from typing import Any, ClassVar
from uuid import UUID

Expand Down Expand Up @@ -93,7 +94,15 @@ def build_template_config(self) -> dict:
if not self._code:
return {}

cc_class = eval_custom_component_code(self._code)
try:
cc_class = eval_custom_component_code(self._code)

except AttributeError as e:
pattern = r"module '.*?' has no attribute '.*?'"
if re.search(pattern, str(e)):
raise ImportError(e) from e
raise

component_instance = cc_class(_code=self._code)
return self.get_template_config(component_instance)

Expand Down
3 changes: 2 additions & 1 deletion src/backend/base/langflow/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .data import Data
from .dotdict import dotdict
from .message import Message

__all__ = ["Data", "dotdict"]
__all__ = ["Data", "dotdict", "Message"]

0 comments on commit 87bf220

Please sign in to comment.