Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#3,044 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@chauvuusvn đang làm issue này rồi.

Từ ngày 3/10/2026.

  • #3045 của @chauvuusvn — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu trong google/genai/_extra_utils.py tại convert_if_exist_pydantic_model và tái hiện các ví dụ typing.List và typing.Dict từ issue. Kiểm tra hành vi khi get_args(annotation) rỗng, sau đó xác minh rằng cả hai lệnh gọi đều trả về các giá trị ban đầu mà không phát sinh lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

priority: p2 type: bug
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.

Ngôn ngữ chính
Python
Star
4k
Fork
1k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
52

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googleapis/python-genai

Tất cả issue của googleapis/python-genai

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.