diff --git a/libs/community/langchain_community/chat_message_histories/dynamodb.py b/libs/community/langchain_community/chat_message_histories/dynamodb.py index 4429d2e1f1b85..2f1c18c45cddf 100644 --- a/libs/community/langchain_community/chat_message_histories/dynamodb.py +++ b/libs/community/langchain_community/chat_message_histories/dynamodb.py @@ -103,7 +103,7 @@ def __init__( ) @property - def messages(self) -> List[BaseMessage]: # type: ignore + def messages(self) -> List[BaseMessage]: """Retrieve the messages from DynamoDB""" try: from botocore.exceptions import ClientError @@ -129,6 +129,13 @@ def messages(self) -> List[BaseMessage]: # type: ignore messages = messages_from_dict(items) return messages + @messages.setter + def messages(self, messages: List[BaseMessage]) -> None: + raise NotImplementedError( + "Direct assignment to 'messages' is not allowed." + " Use the 'add_messages' instead." + ) + def add_message(self, message: BaseMessage) -> None: """Append the message to the record in DynamoDB""" try: diff --git a/libs/community/langchain_community/chat_message_histories/elasticsearch.py b/libs/community/langchain_community/chat_message_histories/elasticsearch.py index bbd621b98d9cc..b164f0e68928b 100644 --- a/libs/community/langchain_community/chat_message_histories/elasticsearch.py +++ b/libs/community/langchain_community/chat_message_histories/elasticsearch.py @@ -141,7 +141,7 @@ def connect_to_elasticsearch( return es_client @property - def messages(self) -> List[BaseMessage]: # type: ignore[override] + def messages(self) -> List[BaseMessage]: """Retrieve the messages from Elasticsearch""" try: from elasticsearch import ApiError @@ -165,6 +165,13 @@ def messages(self) -> List[BaseMessage]: # type: ignore[override] return messages_from_dict(items) + @messages.setter + def messages(self, messages: List[BaseMessage]) -> None: + raise NotImplementedError( + "Direct assignment to 'messages' is not allowed." + " Use the 'add_messages' instead." + ) + def add_message(self, message: BaseMessage) -> None: """Add a message to the chat session in Elasticsearch""" try: