Skip to content

Commit

Permalink
refactor: Simplify _process_raw_result method in custom component pro…
Browse files Browse the repository at this point in the history
…cessing (#6040)

* 🐛 (component.py): fix logic in _process_raw_result method to correctly extract data from result object based on conditions and return it

* [autofix.ci] apply automated fixes

* ♻️ (component.py): refactor extract_data method to improve readability and maintainability by using more descriptive variable names and simplifying the logic.

* [autofix.ci] apply automated fixes

* 🐛 (component.py): update isinstance check to use union type for better type handling

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent 0514d11 commit c2411d4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/backend/base/langflow/custom/custom_component/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,17 +978,20 @@ def _build_artifact(self, result):
return {"repr": custom_repr, "raw": raw, "type": artifact_type}

def _process_raw_result(self, result):
if len(self.outputs) == 1:
return self.status or self.extract_data(result)
return self.extract_data(result)

def extract_data(self, result):
if hasattr(result, "data"):
return result.data
if hasattr(result, "model_dump"):
return result.model_dump()
if isinstance(result, Data | dict | str):
return result.data if isinstance(result, Data) else result
if self.status:
raw = self.status
elif hasattr(result, "data"):
raw = result.data
elif hasattr(result, "model_dump"):
raw = result.model_dump()
elif isinstance(result, dict | Data | str):
raw = result.data if isinstance(result, Data) else result
else:
raw = result
return raw
return self.status
return result

def _log_output(self, output):
self._output_logs[output.name] = self._logs
Expand Down

0 comments on commit c2411d4

Please sign in to comment.