Repository: deepset-ai/haystack

Issue:
Rename `deserialize_document_store_in_init_parameters` to indicate inplace modification
`haystack.util.deserialize_document_store_in_init_parameters` deserializes the document store inplace, but the function's name doesn't indicate that. We should rename it and remove its return value.

Discussion:

Solution patch:
diff --git a/haystack/components/caching/cache_checker.py b/haystack/components/caching/cache_checker.py
index 0ba1e43168..b67608b075 100644
--- a/haystack/components/caching/cache_checker.py
+++ b/haystack/components/caching/cache_checker.py
@@ -6,7 +6,7 @@
 
 from haystack import Document, component, default_from_dict, default_to_dict, logging
 from haystack.document_stores.types import DocumentStore
-from haystack.utils import deserialize_document_store_in_init_parameters
+from haystack.utils import deserialize_document_store_in_init_params_inplace
 
 logger = logging.getLogger(__name__)
 
@@ -73,7 +73,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "CacheChecker":
             Deserialized component.
         """
         # deserialize the document store
-        data = deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
         return default_from_dict(cls, data)
 
diff --git a/haystack/components/retrievers/filter_retriever.py b/haystack/components/retrievers/filter_retriever.py
index 0f69770a31..6f9ad78b3d 100644
--- a/haystack/components/retrievers/filter_retriever.py
+++ b/haystack/components/retrievers/filter_retriever.py
@@ -6,7 +6,7 @@
 
 from haystack import Document, component, default_from_dict, default_to_dict, logging
 from haystack.document_stores.types import DocumentStore
-from haystack.utils import deserialize_document_store_in_init_parameters
+from haystack.utils import deserialize_document_store_in_init_params_inplace
 
 logger = logging.getLogger(__name__)
 
@@ -78,7 +78,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "FilterRetriever":
             The deserialized component.
         """
         # deserialize the document store
-        data = deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
         return default_from_dict(cls, data)
 
diff --git a/haystack/components/retrievers/sentence_window_retriever.py b/haystack/components/retrievers/sentence_window_retriever.py
index 7ec000f76e..36cc5c23fe 100644
--- a/haystack/components/retrievers/sentence_window_retriever.py
+++ b/haystack/components/retrievers/sentence_window_retriever.py
@@ -6,7 +6,7 @@
 
 from haystack import Document, component, default_from_dict, default_to_dict
 from haystack.document_stores.types import DocumentStore
-from haystack.utils import deserialize_document_store_in_init_parameters
+from haystack.utils import deserialize_document_store_in_init_params_inplace
 
 
 @component
@@ -131,7 +131,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "SentenceWindowRetriever":
             Deserialized component.
         """
         # deserialize the document store
-        data = deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
         # deserialize the component
         return default_from_dict(cls, data)
diff --git a/haystack/components/writers/document_writer.py b/haystack/components/writers/document_writer.py
index bd1fa3138f..7e75759638 100644
--- a/haystack/components/writers/document_writer.py
+++ b/haystack/components/writers/document_writer.py
@@ -6,7 +6,7 @@
 
 from haystack import Document, component, default_from_dict, default_to_dict, logging
 from haystack.document_stores.types import DocumentStore, DuplicatePolicy
-from haystack.utils import deserialize_document_store_in_init_parameters
+from haystack.utils import deserialize_document_store_in_init_params_inplace
 
 logger = logging.getLogger(__name__)
 
@@ -74,7 +74,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "DocumentWriter":
             If the document store is not properly specified in the serialization data or its type cannot be imported.
         """
         # deserialize the document store
-        data = deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
         data["init_parameters"]["policy"] = DuplicatePolicy[data["init_parameters"]["policy"]]
 
diff --git a/haystack/utils/__init__.py b/haystack/utils/__init__.py
index baefe8fa06..dd89ad8264 100644
--- a/haystack/utils/__init__.py
+++ b/haystack/utils/__init__.py
@@ -5,7 +5,7 @@
 from .auth import Secret, deserialize_secrets_inplace
 from .callable_serialization import deserialize_callable, serialize_callable
 from .device import ComponentDevice, Device, DeviceMap, DeviceType
-from .docstore_deserialization import deserialize_document_store_in_init_parameters
+from .docstore_deserialization import deserialize_document_store_in_init_params_inplace
 from .expit import expit
 from .filters import document_matches_filter
 from .jupyter import is_in_jupyter
@@ -27,5 +27,5 @@
     "deserialize_callable",
     "serialize_type",
     "deserialize_type",
-    "deserialize_document_store_in_init_parameters",
+    "deserialize_document_store_in_init_params_inplace",
 ]
diff --git a/haystack/utils/docstore_deserialization.py b/haystack/utils/docstore_deserialization.py
index 419a2fa0cd..41d8b2714d 100644
--- a/haystack/utils/docstore_deserialization.py
+++ b/haystack/utils/docstore_deserialization.py
@@ -8,9 +8,9 @@
 from haystack.core.serialization import default_from_dict, import_class_by_name
 
 
-def deserialize_document_store_in_init_parameters(data: Dict[str, Any], key: str = "document_store") -> Dict[str, Any]:
+def deserialize_document_store_in_init_params_inplace(data: Dict[str, Any], key: str = "document_store"):
     """
-    Deserializes a generic document store from the init_parameters of a serialized component.
+    Deserializes a generic document store from the init_parameters of a serialized component in place.
 
     :param data:
         The dictionary to deserialize from.
@@ -37,5 +37,3 @@ def deserialize_document_store_in_init_parameters(data: Dict[str, Any], key: str
         data["init_parameters"][key] = doc_store_class.from_dict(doc_store_data)
     else:
         data["init_parameters"][key] = default_from_dict(doc_store_class, doc_store_data)
-
-    return data
diff --git a/releasenotes/notes/refactor_deserialize_document_store_in_init_parameters-b7f05173f0c56452.yaml b/releasenotes/notes/refactor_deserialize_document_store_in_init_parameters-b7f05173f0c56452.yaml
new file mode 100644
index 0000000000..500f0f4f60
--- /dev/null
+++ b/releasenotes/notes/refactor_deserialize_document_store_in_init_parameters-b7f05173f0c56452.yaml
@@ -0,0 +1,5 @@
+---
+enhancements:
+  - |
+    Refactor deserialize_document_store_in_init_parameters so that new function name
+   indicates that the operation occurs in place, with no return value. 


Test patch:
diff --git a/test/utils/test_docstore_deserialization.py b/test/utils/test_docstore_deserialization.py
index 7a70ad37ee..ffce99dd2c 100644
--- a/test/utils/test_docstore_deserialization.py
+++ b/test/utils/test_docstore_deserialization.py
@@ -6,7 +6,7 @@
 import pytest
 
 from haystack.document_stores.in_memory.document_store import InMemoryDocumentStore
-from haystack.utils.docstore_deserialization import deserialize_document_store_in_init_parameters
+from haystack.utils.docstore_deserialization import deserialize_document_store_in_init_params_inplace
 from haystack.core.errors import DeserializationError
 
 
@@ -14,7 +14,7 @@ class FakeDocumentStore:
     pass
 
 
-def test_deserialize_document_store_in_init_parameters():
+def test_deserialize_document_store_in_init_params_inplace():
     data = {
         "type": "haystack.components.writers.document_writer.DocumentWriter",
         "init_parameters": {
@@ -25,8 +25,8 @@ def test_deserialize_document_store_in_init_parameters():
         },
     }
 
-    result = deserialize_document_store_in_init_parameters(data)
-    assert isinstance(result["init_parameters"]["document_store"], InMemoryDocumentStore)
+    deserialize_document_store_in_init_params_inplace(data)
+    assert isinstance(data["init_parameters"]["document_store"], InMemoryDocumentStore)
 
 
 def test_from_dict_is_called():
@@ -42,7 +42,7 @@ def test_from_dict_is_called():
     }
 
     with patch.object(InMemoryDocumentStore, "from_dict") as mock_from_dict:
-        deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
         mock_from_dict.assert_called_once_with(
             {"type": "haystack.document_stores.in_memory.document_store.InMemoryDocumentStore", "init_parameters": {}}
@@ -59,7 +59,7 @@ def test_default_from_dict_is_called():
     }
 
     with patch("haystack.utils.docstore_deserialization.default_from_dict") as mock_default_from_dict:
-        deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
         mock_default_from_dict.assert_called_once_with(
             FakeDocumentStore, {"type": "test_docstore_deserialization.FakeDocumentStore", "init_parameters": {}}
@@ -69,13 +69,13 @@ def test_default_from_dict_is_called():
 def test_missing_document_store_key():
     data = {"init_parameters": {"policy": "SKIP"}}
     with pytest.raises(DeserializationError):
-        deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
 
 def test_missing_type_key_in_document_store():
     data = {"init_parameters": {"document_store": {"init_parameters": {}}, "policy": "SKIP"}}
     with pytest.raises(DeserializationError):
-        deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)
 
 
 def test_invalid_class_import():
@@ -86,4 +86,4 @@ def test_invalid_class_import():
         }
     }
     with pytest.raises(DeserializationError):
-        deserialize_document_store_in_init_parameters(data)
+        deserialize_document_store_in_init_params_inplace(data)