bug in the AmazonBedrockChatGenerator serialization
Closed this issue · 1 comments
FloRul commented
Describe the bug
The serialize_callable function in callable_serialization.py throws an AttributeError when the callable_handle argument is None.
Error message
AttributeError: 'NoneType' object has no attribute 'name'
File "~\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "~\.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "~test.py", line 21, in <module>
main()
File "~/test.py", line 14, in main
yyy = p.dumps()
^^^^^^^^^
File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\core\pipeline\pipeline.py", line 196, in dumps
return marshaller.marshal(self.to_dict())
^^^^^^^^^^^^^^
File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\core\pipeline\pipeline.py", line 118, in to_dict
components[name] = component_to_dict(instance)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\core\serialization.py", line 24, in component_to_dict
return obj.to_dict()
^^^^^^^^^^^^^
File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack_integrations\components\generators\amazon_bedrock\chat\chat_generator.py", line 223, in to_dict
streaming_callback=serialize_callable(self.streaming_callback),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\AppData\Local\Programs\Python\Python311\Lib\site-packages\haystack\utils\callable_serialization.py", line 20, in serialize_callable
full_path = callable_handle.__name__
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?
Expected behavior
The function should handle the case where callable_handle is None and raise a more descriptive error message. For example, it could raise a ValueError with the message "callable_handle must be a callable, not None".
Additional context
This issue occurs when trying to serialize a None value as a callable, which is not a valid operation.
To reproduce the behavior:
from haystack_integrations.components.generators.amazon_bedrock import (
AmazonBedrockChatGenerator,
)
from haystack import Pipeline
def main():
p = Pipeline()
p.add_component(
"generator",
# can be any chat supported model
AmazonBedrockChatGenerator(model="anthropic.claude-3-sonnet-20240229-v1:0"),
)
print(p.dumps())
if __name__ == "__main__":
main()
FAQ Check
Have you had a look at our new FAQ page?
Yes
System:
OS: Windows
GPU/CPU: I7
Haystack version (commit or version number): Version: 2.0.1
anakin87 commented
duplicate of deepset-ai/haystack-core-integrations#684
fixed in deepset-ai/haystack-core-integrations#685