mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 08:57:31 +08:00
fix: Allow variable retrieval without user_id if in context (#11052)
* Allow variable retrieval without user_id if in context Updated CustomComponent to first check for variables in the request context before requiring a user_id. This enables run_flow and similar operations to work without a user_id when variables are provided in the context, improving flexibility and error handling. * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * [autofix.ci] apply automated fixes (attempt 3/3) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user