Skip to content

fix: handle null API responses and add debug logging#15

Merged
shaiu merged 1 commit intodevfrom
shaiu/fix-none-response-add-debug-logging
Mar 7, 2026
Merged

fix: handle null API responses and add debug logging#15
shaiu merged 1 commit intodevfrom
shaiu/fix-none-response-add-debug-logging

Conversation

@shaiu
Copy link
Copy Markdown
Owner

@shaiu shaiu commented Mar 7, 2026

Describe what the PR does:

  • Guard against null summary_resp and packages_resp (and their Json field) to fix AttributeError when 17track returns {"Json": null}
  • Add debug logging in _request for HTTP status, content-type, and raw body
  • Add warning log when JSON parsing returns None
  • Bump version to 1.1.2

Checklist:

  • Confirm that one or more new tests are written for the new functionality.
  • Run tests and ensure everything passes (with 100% test coverage).
  • Update README.md with any new documentation.
  • Add yourself to AUTHORS.md.

- Guard against null summary_resp and packages_resp (and their Json field)
  to fix AttributeError when 17track returns {"Json": null}
- Add debug logging in _request for HTTP status, content-type, and raw body
- Add warning log when JSON parsing returns None
- Bump version to 1.1.2

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the robustness of the 17track.net API client by implementing comprehensive null checks for API responses, preventing potential AttributeError exceptions. It also enhances debug logging for API requests and responses, providing better visibility into network interactions and data parsing, which will aid in troubleshooting. The package version has been updated to reflect these important changes.

Highlights

  • API Response Robustness: Implemented null checks for summary_resp and packages_resp to prevent AttributeError when the 17track API returns {"Json": null}.
  • Enhanced Debug Logging: Added debug logging in the _request function to include HTTP status, content-type, and the raw response body for better introspection.
  • JSON Parsing Warning: Introduced a warning log when JSON parsing of an API response yields None, indicating a potentially malformed or empty response.
  • Version Update: Bumped the package version from 1.1.1 to 1.1.2.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • pyproject.toml
    • Updated the project version from 1.1.1 to 1.1.2.
  • pyseventeentrack/client.py
    • Imported the logging module and initialized a logger instance.
    • Added debug logs to _request to show HTTP status, content-type, and raw response body.
    • Introduced a warning log if the JSON response from the API is parsed as None.
  • pyseventeentrack/profile.py
    • Modified the packages function to safely access Json and its contents using or {} and or [] to handle potential null responses.
    • Modified the summary function to safely access Json and eitem using or {} to handle potential null responses.
Activity
  • The author has confirmed that new tests have been written for the new functionality.
  • The author has run tests and ensured everything passes with 100% test coverage.
  • Remaining tasks include updating README.md and AUTHORS.md.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@shaiu shaiu merged commit 4143ee1 into dev Mar 7, 2026
7 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses potential AttributeError exceptions from null API responses and adds valuable debug logging, improving the robustness of the client. No security vulnerabilities were found. My review includes suggestions to enhance type safety and improve code readability, especially for complex null-checking expressions, to improve maintainability.

resp.raise_for_status()
raw: str = await resp.text()
_LOGGER.debug("Raw response body from %s: %r", url, raw)
data: dict = await resp.json(content_type=None)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The type hint for data is dict, but resp.json() can return None, as you correctly check on the following lines. This creates a type inconsistency. To fix this, the type hint for data should be Optional[dict].

Additionally, the return type hint for the _request function (on line 38) should be updated from -> dict to -> Optional[dict] to accurately reflect that it can return None.

Suggested change
data: dict = await resp.json(content_type=None)
data: Optional[dict] = await resp.json(content_type=None)


packages: List[Package] = []
for package in packages_resp.get("Json", []):
for package in (packages_resp or {}).get("Json") or []:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this line correctly handles potential None values, its density can make it difficult to read and understand at a glance. For better readability and maintainability, consider extracting the package list into a separate variable before the loop.

For example:

package_list = (packages_resp or {}).get("Json") or []
for package in package_list:


results: dict = {}
for kind in summary_resp.get("Json", {}).get("eitem", []):
for kind in ((summary_resp or {}).get("Json") or {}).get("eitem", []):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This line is very dense and hard to read due to the nested safe access patterns. To improve readability and maintainability, it would be better to break this down into multiple steps.

Consider refactoring it like this:

summary_json = (summary_resp or {}).get("Json") or {}
for kind in summary_json.get("eitem", []):

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.

1 participant