langflow-ai/langflow · error · AttributeError
module '{self.__name__}' has no attribute '{name}'
Error message
module '{self.__name__}' has no attribute '{name}' What it means
The lazy compat shim in langflow/__init__.py raises a plain AttributeError ('module ... has no attribute ...') when the forwarded attribute does not exist on the underlying lfx module. This mirrors normal Python semantics so hasattr() and try/except AttributeError keep working through the shim. It almost always means the symbol was renamed or moved during the langflow->lfx migration, not that the shim is broken.
Source
Thrown at src/backend/base/langflow/__init__.py:141
def _get_lfx_module(self):
"""Lazily import and cache the lfx module."""
if self._lfx_module is None:
try:
self._lfx_module = importlib.import_module(self._lfx_module_name)
except ImportError as e:
msg = f"Cannot import {self._lfx_module_name} for backwards compatibility with {self.__name__}"
raise ImportError(msg) from e
return self._lfx_module
def __getattr__(self, name: str) -> Any:
"""Forward attribute access to the lfx module with caching."""
lfx_module = self._get_lfx_module()
try:
attr = getattr(lfx_module, name)
except AttributeError as e:
msg = f"module '{self.__name__}' has no attribute '{name}'"
raise AttributeError(msg) from e
else:
# Cache the attribute in our __dict__ for faster subsequent access
setattr(self, name, attr)
return attr
def __dir__(self):
"""Return directory of the lfx module."""
try:
lfx_module = self._get_lfx_module()
return dir(lfx_module)
except ImportError:
return []
def _setup_compatibility_modules():
"""Set up comprehensive compatibility modules for langflow.base imports."""
# First, set up the base attribute on this module (langflow)
current_module = sys.modules[__name__]View on GitHub (pinned to 976ec789d2)
Solutions
- Check what the lfx module actually exports: 'uv run python -c "import lfx; print([n for n in dir(lfx) if 'Chat' in n])"' and use the current name.
- Search the repo for the new location: the symbol likely moved to lfx (grep for 'class <Symbol>' under src/lfx or src/backend).
- If you maintain the shim mapping, add the missing re-export explicitly rather than relying on forwarding.
- Pin to the langflow version whose API your code was written against until you migrate names.
Example fix
# before from langflow import ChatInput # AttributeError: module 'langflow' has no attribute 'ChatInput' # after: use the current lfx name from lfx.chat import ChatInput
Defensive patterns
Strategy: type-guard
Validate before calling
import langflow name = "ChatInput" has_it = hasattr(langflow, name) # goes through the shim's __getattr__ safely
Type guard
def has_langflow_symbol(mod, name: str) -> bool:
"""True if the lazy compat shim can resolve the symbol."""
return hasattr(mod, name) Try / catch
try:
Symbol = langflow.ChatInput
except AttributeError as e:
raise NotImplementedError(
f"{e}: symbol was renamed/moved in the lfx migration — import from lfx directly"
) from e Prevention
- Prefer importing new code from lfx directly; treat langflow.* forwarding as legacy.
- Pin versions while migrating custom components across the langflow->lfx split.
- Use hasattr() before optional attribute access through the shim.
When it happens
Trigger: Accessing langflow.SomeSymbol where SomeSymbol exists neither in the legacy package's __dict__ nor on the lfx module the shim forwards to; using a symbol that was renamed/removed in the current lfx version.
Common situations: Upgrading across the langflow->lfx code move where a class or function was renamed (e.g. component base classes); stale custom code referencing pre-migration names; typo'd attribute that only fails at runtime due to lazy forwarding.
Related errors
- Cannot import {self._lfx_module_name} for backwards compatib
- The '{provider}' components moved to the 'lfx-bundles' distr
- Could not import {attr_name!r} from {__name__!r}: {e}
- Could not load flow module: {flow_path}
- Error loading flow module: {e}
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/8a54918a4ec0cfb2.
Report an issue: GitHub.