Skip to content

Fix google_genai integration crash when Gemini returns parts=None#1678

Merged
alexmojaki merged 8 commits intomainfrom
claude/issue-1675-20260130-0838
Jan 30, 2026
Merged

Fix google_genai integration crash when Gemini returns parts=None#1678
alexmojaki merged 8 commits intomainfrom
claude/issue-1675-20260130-0838

Conversation

@alexmojaki
Copy link
Copy Markdown
Collaborator

Summary

  • Fix TypeError when Gemini 3 Pro returns thinking-only response with parts=None
  • Add test for the parts=None scenario

Fixes #1675

Generated with Claude Code

When Gemini 3 Pro returns a thinking-only response with no text or tool
calls, the 'parts' field can be None. This caused a TypeError when trying
to iterate over None in the SpanEventLogger.emit method.

Added a simple null check to handle this case gracefully by returning an
empty list when parts is None.

Fixes #1675

Co-authored-by: Alex Hall <alexmojaki@users.noreply.github.com>
@alexmojaki
Copy link
Copy Markdown
Collaborator Author

@claude make CI pass

@claude
Copy link
Copy Markdown

claude bot commented Jan 30, 2026

Claude encountered an error after 3m 10s —— View job


Making CI Pass

  • Check CI status and identify failing jobs
  • Fix lint error (import sorting in test file)
  • Verify CI passes

Fixed issues:

  1. Lint failure: Import block is un-sorted in tests/otel_integrations/test_google_genai.py:290

Fixed import ordering (third-party imports before first-party) in commit ea37dad. CI is running...
|

Co-authored-by: Alex Hall <alexmojaki@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Jan 30, 2026

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 032e9f6
Status: ✅  Deploy successful!
Preview URL: https://e03e4b8a.logfire-docs.pages.dev
Branch Preview URL: https://claude-issue-1675-20260130-0.logfire-docs.pages.dev

View logs

@alexmojaki
Copy link
Copy Markdown
Collaborator Author

@claude make sure you're configured to always use pre-commit

@claude
Copy link
Copy Markdown

claude bot commented Jan 30, 2026

Claude finished @alexmojaki's task in 26s —— View job


Pre-commit Configuration

  • Acknowledge pre-commit requirement
  • Verify understanding of pre-commit workflow

Understood! I will run pre-commit run --all-files (or at minimum on changed files) before committing changes to catch:

  • Ruff lint - import sorting, code style issues
  • Ruff format - code formatting
  • Pyright - type checking

This would have caught the import sorting issue in the previous commit. Going forward, I'll ensure pre-commit hooks pass before pushing changes.
|

Co-authored-by: Alex Hall <alexmojaki@users.noreply.github.com>
@alexmojaki
Copy link
Copy Markdown
Collaborator Author

@claude you'll forget after this session. i'm asking you to make a permanent visible change to your github config.

@claude
Copy link
Copy Markdown

claude bot commented Jan 30, 2026

Claude finished @alexmojaki's task in 1m 41s —— View job


Pre-commit Hook Configuration

  • Find the GitHub configuration file for Claude Code Action
  • Add hook configuration to settings.json
  • Commit and push the changes

Done! Added a PreToolUse hook to .claude/settings.json that automatically runs pre-commit on staged files before any git commit command.

Changes made:

  • Added Bash(uv run pre-commit:*) to allowed permissions
  • Added a PreToolUse hook that intercepts Bash commands containing git commit and runs uv run pre-commit run --files <staged files> first
  • If pre-commit fails (exit code non-zero), the hook returns exit code 2 which blocks the commit

This configuration will persist across sessions and ensure I always run pre-commit checks before committing.

View job

Configure a PreToolUse hook that automatically runs pre-commit on staged
files before any git commit command. This ensures lint and format checks
pass before committing.

Co-authored-by: Alex Hall <alexmojaki@users.noreply.github.com>
@alexmojaki
Copy link
Copy Markdown
Collaborator Author

@claude that will run pre-commit twice in environments where the commit hook is installed. can you do this normally and install the git hook in your github env at the start?

@claude
Copy link
Copy Markdown

claude bot commented Jan 30, 2026

Claude finished @alexmojaki's task in 1m 33s —— View job


Git Hook Configuration

  • Read current settings.json configuration
  • Research available hook types in Claude Code
  • Update settings.json: Replace PreToolUse hook with SessionStart hook
  • Commit and push changes

Done! Changed the approach from manually running pre-commit before each git commit to installing the git hook at session start.

What changed:

  • Replaced PreToolUse hook (which ran uv run pre-commit run --files ... before every git commit command)
  • Added SessionStart hook that runs uv run pre-commit install once at the start of each session

This way, pre-commit is installed as a normal git hook and only runs once when committing, avoiding the double-run issue.

View job

This avoids running pre-commit twice when the git hook is already installed.
The SessionStart hook installs pre-commit hooks at the start of each session,
then git commit naturally triggers the hook.

Co-authored-by: Alex Hall <alexmojaki@users.noreply.github.com>
@alexmojaki
Copy link
Copy Markdown
Collaborator Author

@claude fix CI

@claude
Copy link
Copy Markdown

claude bot commented Jan 30, 2026

Claude encountered an error after 2m 14s —— View job


Fixing CI

  • Check CI status and identify failing jobs
  • Fix lint issue (formatting in test_google_genai.py)
  • Fix test failure (AssertionError in test_span_event_logger_with_none_parts)
  • Verify CI passes

Found issues:

  1. Lint failure: Formatting issue in tests/otel_integrations/test_google_genai.py - need to run ruff format
  2. Test failure: test_span_event_logger_with_none_parts - assert record.event_name fails at logfire/_internal/integrations/google_genai.py:75

Investigating the test failure...

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a crash in the google_genai integration that occurs when Gemini 3 Pro returns a thinking-only response with parts=None. The fix adds a simple null check and includes comprehensive test coverage.

Changes:

  • Added conditional logic to handle parts=None in the Google GenAI integration
  • Added test case to verify the fix works correctly
  • Refactored test exporter to consolidate attribute building logic

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
logfire/_internal/integrations/google_genai.py Added null check for parts to prevent TypeError when iterating
tests/otel_integrations/test_google_genai.py Added test for parts=None scenario to prevent regression
logfire/_internal/exporters/test.py Refactored to use centralized _build_attributes function, removing duplicate code
.claude/settings.json Added pre-commit hooks configuration (unrelated to bug fix)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alexmojaki alexmojaki enabled auto-merge (squash) January 30, 2026 15:03
@alexmojaki alexmojaki merged commit acae790 into main Jan 30, 2026
14 checks passed
@alexmojaki alexmojaki deleted the claude/issue-1675-20260130-0838 branch January 30, 2026 15:09
@cmorrison3r3
Copy link
Copy Markdown

Thanks so much!

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.

google_genai integration crashes when Gemini returns parts = None

3 participants