Skip to content

If "sentiment" is on, field access fails due to incorrect from_dict() call on StrEnum #571

@francescopuddu

Description

@francescopuddu

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

  1. Make a transcription request that returns sentiment analysis data
  2. Try to access any field from the response object using bracket notation (e.g.,
    response["results"])
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions