Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 (component.py): fix logic in _process_raw_result method to correctl…
Browse files Browse the repository at this point in the history
…y extract data from result object based on conditions and return it
Cristhianzl committed Jan 31, 2025
1 parent 5804336 commit 263f4d2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/backend/base/langflow/custom/custom_component/component.py
Original file line number Diff line number Diff line change
@@ -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 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
if len(self.outputs) == 1:
return self.status or self.extract_data(result)
return self.extract_data(result)

Check failure on line 984 in src/backend/base/langflow/custom/custom_component/component.py

GitHub Actions / Ruff Style Check (3.12)

Ruff (W293)

src/backend/base/langflow/custom/custom_component/component.py:984:1: W293 Blank line contains whitespace
def extract_data(self, r):
if hasattr(r, "data"):
return r.data
elif hasattr(r, "model_dump"):

Check failure on line 988 in src/backend/base/langflow/custom/custom_component/component.py

GitHub Actions / Ruff Style Check (3.12)

Ruff (RET505)

src/backend/base/langflow/custom/custom_component/component.py:988:9: RET505 Unnecessary `elif` after `return` statement
return r.model_dump()
elif isinstance(r, (Data, dict, str)):

Check failure on line 990 in src/backend/base/langflow/custom/custom_component/component.py

GitHub Actions / Ruff Style Check (3.12)

Ruff (UP038)

src/backend/base/langflow/custom/custom_component/component.py:990:14: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`
return r.data if isinstance(r, Data) else r
elif self.status:
return self.status
return r

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

0 comments on commit 263f4d2

Please sign in to comment.