Skip to content

Commit c2411d4

Browse files
Cristhianzlautofix-ci[bot]ogabrielluiz
authored
refactor: Simplify _process_raw_result method in custom component processing (#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 <gabriel@langflow.org>
1 parent 0514d11 commit c2411d4

File tree

1 file changed

+13
-10
lines changed
  • src/backend/base/langflow/custom/custom_component

1 file changed

+13
-10
lines changed

src/backend/base/langflow/custom/custom_component/component.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -978,17 +978,20 @@ def _build_artifact(self, result):
978978
return {"repr": custom_repr, "raw": raw, "type": artifact_type}
979979

980980
def _process_raw_result(self, result):
981+
if len(self.outputs) == 1:
982+
return self.status or self.extract_data(result)
983+
return self.extract_data(result)
984+
985+
def extract_data(self, result):
986+
if hasattr(result, "data"):
987+
return result.data
988+
if hasattr(result, "model_dump"):
989+
return result.model_dump()
990+
if isinstance(result, Data | dict | str):
991+
return result.data if isinstance(result, Data) else result
981992
if self.status:
982-
raw = self.status
983-
elif hasattr(result, "data"):
984-
raw = result.data
985-
elif hasattr(result, "model_dump"):
986-
raw = result.model_dump()
987-
elif isinstance(result, dict | Data | str):
988-
raw = result.data if isinstance(result, Data) else result
989-
else:
990-
raw = result
991-
return raw
993+
return self.status
994+
return result
992995

993996
def _log_output(self, output):
994997
self._output_logs[output.name] = self._logs

0 commit comments

Comments
 (0)