diff --git a/src/lfx/src/lfx/custom/custom_component/custom_component.py b/src/lfx/src/lfx/custom/custom_component/custom_component.py index 61afb41696..444ff7d71a 100644 --- a/src/lfx/src/lfx/custom/custom_component/custom_component.py +++ b/src/lfx/src/lfx/custom/custom_component/custom_component.py @@ -456,24 +456,26 @@ class CustomComponent(BaseComponent): """Returns the variable for the current user with the specified name. Raises: - ValueError: If the user id is not set. + ValueError: If the user id is not set and variable not found in context. Returns: The variable for the current user with the specified name. """ - if hasattr(self, "_user_id") and not self.user_id: - msg = f"User id is not set for {self.__class__.__name__}" - raise ValueError(msg) - # Check graph context for request-level variable overrides first + # This allows run_flow to work without user_id when variables are passed if hasattr(self, "graph") and self.graph and hasattr(self.graph, "context"): context = self.graph.context if context and "request_variables" in context: request_variables = context["request_variables"] if name in request_variables: - logger.debug(f"Found context override for variable '{name}': {request_variables[name]}") + logger.debug(f"Found context override for variable '{name}'") return request_variables[name] + # Only check user_id when we need to access the database + if hasattr(self, "_user_id") and not self.user_id: + msg = f"User id is not set for {self.__class__.__name__}" + raise ValueError(msg) + variable_service = get_variable_service() # Get service instance # Retrieve and decrypt the variable by name for the current user if isinstance(self.user_id, str):