deepgram-python-sdk
deepgram-python-sdk copied to clipboard
If "sentiment" is on, field access fails due to incorrect from_dict() call on StrEnum
What is the current behavior?
Location:
.venv/lib/python3.12/site-packages/deepgram/clients/listen/v1/rest/response.py
lines 169-173
Problematic code:
def __getitem__(self, key):
_dict = self.to_dict()
if "sentiment" in _dict:
_dict["sentiment"] = Sentiment.from_dict(_dict["sentiment"]) # this line
has no from_dict method
return _dict[key]
The __getitem__ method in the Deepgram response class attempts to call
Sentiment.from_dict() on the sentiment field, but Sentiment is a StrEnum that
doesn't have a from_dict() method. This causes an AttributeError when accessing
any field from the response object when sentiment data is present.
Steps to reproduce
- Make a transcription request that returns sentiment analysis data
- Try to access any field from the response object using bracket notation (e.g.,
response["results"]) - The error occurs in the
__getitem__method when it tries to process the sentiment field
Expected behavior
The response object should allow normal field access without errors.
Please tell us about your environment
- Operating System/Version: macOS 14.6.0
- Python Version: 3.12
Suggested fix: Since Sentiment is a StrEnum, the sentiment value is already in the correct format and doesn't need conversion. The problematic lines should be removed or the sentiment field should be handled differently.