Skip to content

fix:fixes endpoint issue #526

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

Closed
wants to merge 1 commit into from
Closed

fix:fixes endpoint issue #526

wants to merge 1 commit into from

Conversation

jpvajda
Copy link
Contributor

@jpvajda jpvajda commented May 14, 2025

Proposed changes

Proposes a fix for #525

Types of changes

What types of changes does your code introduce to the community Python SDK?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update or tests (if none of the other choices apply)

Summary by CodeRabbit

  • New Features

    • Improved flexibility for specifying headers, allowing both dictionary and list formats.
    • Added support for consistent serialization of headers to a dictionary format.
  • Bug Fixes

    • Enhanced handling of headers to ensure compatibility and reliability across different formats.

@jpvajda jpvajda requested a review from naomi-lgbt May 14, 2025 16:22
Copy link
Contributor

coderabbitai bot commented May 14, 2025

Walkthrough

The Endpoint dataclass in the websocket options module was updated to allow its headers attribute to accept either a dictionary or a list of Header objects. The __getitem__ method and a new to_dict method were added or modified to handle this dual representation and ensure consistent serialization.

Changes

File(s) Change Summary
deepgram/clients/agent/v1/websocket/options.py Updated Endpoint.headers type annotation to accept Dict[str, str] or List[Header]; modified __getitem__ to handle both types; added to_dict method for consistent dictionary serialization of headers.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Endpoint

    Client->>Endpoint: Initialize with headers (dict or list)
    Client->>Endpoint: Access headers via __getitem__
    Endpoint-->>Client: Return headers as dict or list
    Client->>Endpoint: Call to_dict()
    Endpoint-->>Client: Return headers as dict
Loading

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 052aadd and f265d89.

📒 Files selected for processing (1)
  • deepgram/clients/agent/v1/websocket/options.py (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check - static
deepgram/clients/agent/v1/websocket/options.py

[error] 96-96: mypy type checking error: Signature of 'to_dict' incompatible with supertype 'DataClassJsonMixin'. Expected 'to_dict(self, encode_json: Any = ...) -> dict[str, dict[Any, Any] | list[Any] | str | int | float | bool | None]', but found 'to_dict(self) -> dict[Any, Any]'.

🪛 GitHub Actions: Check - lint
deepgram/clients/agent/v1/websocket/options.py

[warning] 96-96: pylint W0221: Number of parameters was 2 in 'DataClassJsonMixin.to_dict' and is now 1 in overriding 'Endpoint.to_dict' method (arguments-differ)

🔇 Additional comments (3)
deepgram/clients/agent/v1/websocket/options.py (3)

5-5: Appropriate import additions

The additions of Union and Dict to the imports are necessary to support the new type annotation for the headers attribute in the Endpoint class.


80-82: LGTM: Type annotation change supports both dictionary and list types

This change allows headers to be represented either as a dictionary or as a list of Header objects, which appears to be the core of the bugfix for the endpoint issue.


87-94: Properly handles both dictionary and list representations

The __getitem__ method now correctly handles both cases:

  • If headers is a list, it ensures each entry is a Header object
  • If headers is a dictionary, it preserves the dictionary structure

This implementation properly supports the dual representation of headers.

Comment on lines +96 to +107
def to_dict(self) -> dict:
"""
Convert the endpoint to a dictionary, properly handling headers.
"""
result = super().to_dict()
if self.headers:
if isinstance(self.headers, dict):
result["headers"] = self.headers
else:
result["headers"] = {h.key: h.value for h in self.headers}
return result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Fix the method signature to match parent class

The to_dict method implementation has a signature that's incompatible with the parent class, which is causing pipeline failures.

-    def to_dict(self) -> dict:
+    def to_dict(self, encode_json=False) -> dict:

The error messages from the CI pipeline indicate:

  • mypy error: Signature incompatible with supertype 'DataClassJsonMixin'
  • pylint warning: Number of parameters was 2 in 'DataClassJsonMixin.to_dict' and is now 1 in overriding method

The method needs to maintain the same signature as the parent class while implementing the additional logic to handle the headers properly.


🏁 Script executed:

#!/bin/bash
# Check the signature of DataClassJsonMixin.to_dict
rg -A 5 "def to_dict" --glob="*.py" | grep -A 5 "class.*DataClassJsonMixin"

Length of output: 77


🏁 Script executed:

#!/bin/bash
# Verify the signature of DataClassJsonMixin.to_dict from the dataclasses-json library
pip install dataclasses-json
python3 - << 'EOF'
from dataclasses_json import DataClassJsonMixin
import inspect
src = inspect.getsource(DataClassJsonMixin.to_dict)
sig = inspect.signature(DataClassJsonMixin.to_dict)
print("Source of DataClassJsonMixin.to_dict:")
print(src)
print("Signature of DataClassJsonMixin.to_dict:", sig)
EOF

Length of output: 1375


Fix to_dict signature to match DataClassJsonMixin
The parent class defines to_dict(self, encode_json=False), so your override must include the same parameter and pass it through to super(). Without this change, mypy and pylint will continue to report an incompatible signature.

• File: deepgram/clients/agent/v1/websocket/options.py (lines 96–107)
• Update method signature and the call to super().to_dict

-    def to_dict(self) -> dict:
+    def to_dict(self, encode_json=False) -> dict:
         """
         Convert the endpoint to a dictionary, properly handling headers.
         """
-        result = super().to_dict()
+        result = super().to_dict(encode_json=encode_json)
         if self.headers:
             if isinstance(self.headers, dict):
                 result["headers"] = self.headers
             else:
                 result["headers"] = {h.key: h.value for h in self.headers}
         return result

— Signature verified via inspect.signature(DataClassJsonMixin.to_dict) returning (self, encode_json=False)

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def to_dict(self) -> dict:
"""
Convert the endpoint to a dictionary, properly handling headers.
"""
result = super().to_dict()
if self.headers:
if isinstance(self.headers, dict):
result["headers"] = self.headers
else:
result["headers"] = {h.key: h.value for h in self.headers}
return result
def to_dict(self, encode_json=False) -> dict:
"""
Convert the endpoint to a dictionary, properly handling headers.
"""
result = super().to_dict(encode_json=encode_json)
if self.headers:
if isinstance(self.headers, dict):
result["headers"] = self.headers
else:
result["headers"] = {h.key: h.value for h in self.headers}
return result
🧰 Tools
🪛 GitHub Actions: Check - static

[error] 96-96: mypy type checking error: Signature of 'to_dict' incompatible with supertype 'DataClassJsonMixin'. Expected 'to_dict(self, encode_json: Any = ...) -> dict[str, dict[Any, Any] | list[Any] | str | int | float | bool | None]', but found 'to_dict(self) -> dict[Any, Any]'.

🪛 GitHub Actions: Check - lint

[warning] 96-96: pylint W0221: Number of parameters was 2 in 'DataClassJsonMixin.to_dict' and is now 1 in overriding 'Endpoint.to_dict' method (arguments-differ)

🤖 Prompt for AI Agents (early access)
In deepgram/clients/agent/v1/websocket/options.py lines 96 to 107, the to_dict
method signature does not match the parent class DataClassJsonMixin's to_dict,
which expects a parameter encode_json with a default value. Update the method
signature to include encode_json=False and pass this parameter when calling
super().to_dict to ensure compatibility and fix the mypy and pylint errors.

@lukeocodes lukeocodes closed this May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants