Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions haystack/core/pipeline/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import heapq
from collections.abc import Callable
from copy import deepcopy
import copy
from functools import wraps
from itertools import count
from typing import Any
Expand Down Expand Up @@ -42,7 +42,16 @@ def _deepcopy_with_exceptions(obj: Any) -> Any:
return type(obj)(_deepcopy_with_exceptions(v) for v in obj)

if isinstance(obj, dict):
return {k: _deepcopy_with_exceptions(v) for k, v in obj.items()}
if type(obj) is dict:
return {k: _deepcopy_with_exceptions(v) for k, v in obj.items()}
try:
new = copy.copy(obj)
new.clear()
for k, v in obj.items():
new[k] = _deepcopy_with_exceptions(v)
return new
except Exception:
return {k: _deepcopy_with_exceptions(v) for k, v in obj.items()}

# Components and Tools often contain objects that we do not want to deepcopy or are not deepcopyable
# (e.g. models, clients, etc.). In this case we return the object as-is.
Expand Down