Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFC

オープン 初心者向け
#3,044 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@chauvuusvn がすでに取り組んでいます。

2026年10月3日 から。

  • #3045 @chauvuusvn による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

google/genai/_extra_utils.py の convert_if_exist_pydantic_model から始め、issue の typing.List と typing.Dict の例を再現します。get_args(annotation) が空の場合の動作を確認し、その後、両方の呼び出しがエラーを発生させずに元の値を返すことを検証します。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

In google/genai/_extra_utils.py, inside convert_if_exist_pydantic_model:

if isinstance(value, list) and get_origin(annotation) == list:
    item_type = get_args(annotation)[0]  # Crashes with IndexError on typing.List
    ...
if isinstance(value, dict) and get_origin(annotation) == dict:
    _, value_type = get_args(annotation) # Crashes with ValueError on typing.Dict
    ...

When a user defines a tool function with unsubscripted generic type annotations like typing.List or typing.Dict:

  • get_origin(List) is list, but get_args(List) returns (). Accessing [0] raises IndexError: tuple index out of range.
  • get_origin(Dict) is dict, but get_args(Dict) returns (). Unpacking _, value_type = get_args(Dict) raises ValueError: not enough values to unpack (expected 2, got 0).

This causes Automatic Function Calling (AFC) to crash during function argument conversion.

Steps to Reproduce
from typing import Dict, List
from google.genai._extra_utils import convert_if_exist_pydantic_model

# 1. Test typing.List
convert_if_exist_pydantic_model([1, 2], List, 'items', 'my_func')
# Raises IndexError: tuple index out of range!

# 2. Test typing.Dict
convert_if_exist_pydantic_model({'a': 1}, Dict, 'config', 'my_func')
# Raises ValueError: not enough values to unpack (expected 2, got 0)!
Expected Behavior

If get_args(annotation) is empty for unsubscripted typing.List or typing.Dict, convert_if_exist_pydantic_model should safely return the original value without raising IndexError or ValueError.

主要言語
Python
スター
4k
フォーク
1k
平均マージ
1日 18時間
マージ済み PR(30日)
52

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

googleapis/python-genai のほかの issue

googleapis/python-genai の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。