New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue: If DynamoDB table does not exist conversation message history fails with "local variable 'response' referenced before assignment" #6088
Comments
Generated by a 🤖 AnswerTo fix the issue, modify the exception handling in the from botocore.exceptions import ClientError
# ...
@property
def messages(self) -> List[BaseMessage]: # type: ignore
"""Retrieve the messages from DynamoDB"""
items = []
try:
response = self.table.get_item(Key={"SessionId": self.session_id})
if "Item" in response:
items = response["Item"]["History"]
except ClientError as error:
if error.response["Error"]["Code"] == "ResourceNotFoundException":
logger.error("DynamoDB table not found: %s", self.table.table_name)
else:
logger.error(error)
messages = messages_from_dict(items)
return messages This change will log an error stating that the DynamoDB table was not found and return an empty list of messages if the table does not exist. SourcesThis response is meant to be helpful and save users time. It is not meant to be a precise solution. Please leave a 👍 if this is helpful and 👎 if it is irrelevant |
…ny chat history. (#6141) <!-- Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights your valuable contribution. After you're done, someone will review your PR. They may suggest improvements. If no one reviews your PR within a few days, feel free to @-mention the same people again, as notifications can get lost. Finally, we'd love to show appreciation for your contribution - if you'd like us to shout you out on Twitter, please also include your handle! --> The current version of chat history with DynamoDB doesn't handle the case correctly when a table has no chat history. This change solves this error handling. <!-- Remove if not applicable --> Fixes #6088 #### Who can review? Tag maintainers/contributors who might be interested: @hwchase17 <!-- For a quicker response, figure out the right person to tag with @ @hwchase17 - project lead Tracing / Callbacks - @agola11 Async - @agola11 DataLoaders - @eyurtsev Models - @hwchase17 - @agola11 Agents / Tools / Toolkits - @hwchase17 VectorStores / Retrievers / Memory - @dev2049 -->
…ny chat history. (langchain-ai#6141) <!-- Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights your valuable contribution. After you're done, someone will review your PR. They may suggest improvements. If no one reviews your PR within a few days, feel free to @-mention the same people again, as notifications can get lost. Finally, we'd love to show appreciation for your contribution - if you'd like us to shout you out on Twitter, please also include your handle! --> The current version of chat history with DynamoDB doesn't handle the case correctly when a table has no chat history. This change solves this error handling. <!-- Remove if not applicable --> Fixes langchain-ai#6088 #### Who can review? Tag maintainers/contributors who might be interested: @hwchase17 <!-- For a quicker response, figure out the right person to tag with @ @hwchase17 - project lead Tracing / Callbacks - @agola11 Async - @agola11 DataLoaders - @eyurtsev Models - @hwchase17 - @agola11 Agents / Tools / Toolkits - @hwchase17 VectorStores / Retrievers / Memory - @dev2049 -->
System Info
If the dyanamodb table does not exist when retrieving conversation history then a generic "local variable 'response' referenced before assignment" error is returned. This is due to the exception handling at https://github.com/hwchase17/langchain/blob/master/langchain/memory/chat_message_histories/dynamodb.py#L50 does not determine if the table does not exist
Who can help?
No response
Information
Related Components
Reproduction
Expected behavior
An error should be logged stating that the dynamodb table was not found
The text was updated successfully, but these errors were encountered: