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>
This commit is contained in:
Cristhian Zanforlin Lousa 2025-01-31 16:11:46 -03:00 committed by GitHub
commit c2411d4c22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -978,17 +978,20 @@ class Component(CustomComponent):
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