JSON numeric getters accept booleans as integers and floats

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

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

@pradeep-ramola đang làm issue này rồi.

Từ ngày 30/11/2026.

  • #936 của @pradeep-ramola — đ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
78/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
backend-api-design

Hướng nghiên cứu

Bắt đầu với JsonParseNode.get_int_value() và get_float_value() trong phần triển khai nút phân tích JSON, sau đó lần theo cách các collection kiểu nguyên thủy chuyển đổi từng phần tử. Thêm các hồi quy cho giá trị trực tiếp, các nút con được phân tích bởi JsonParseNodeFactory và các collection được chỉ định kiểu rõ ràng; giữ nguyên các getter boolean, các chuyển đổi số hợp lệ và các collection boolean được suy luận. Hoàn tất khi boolean trả về None từ các getter số và các hồi quy tập trung cùng các kiểm thử đối chứng hiện có đều đạt.

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

Mô tả

Describe the bug

JsonParseNode.get_int_value() accepts JSON booleans as integers, and get_float_value() converts them to 1.0/0.0. This also occurs through child nodes parsed from JSON bytes and in explicitly typed numeric collections.

The implementation uses isinstance(value, int) / isinstance(value, (float, int)). In Python, bool is a subclass of int, but JSON booleans are not numeric tokens. Other non-number values already return None from these getters.

Reproduction

from kiota_serialization_json.json_parse_node import JsonParseNode
from kiota_serialization_json.json_parse_node_factory import JsonParseNodeFactory

print(JsonParseNode(True).get_int_value())       # True
print(JsonParseNode(False).get_float_value())    # 0.0
root = JsonParseNodeFactory().get_root_parse_node(
    "application/json", b'{"count": true}'
)
print(root.get_child_node("count").get_int_value())  # True
print(JsonParseNode([1, True, False, 0]).get_collection_of_primitive_values(float))
# [1.0, 1.0, 0.0, 0.0]

Expected behavior

Boolean inputs should follow the existing non-number path and return None from integer/float getters, rather than silently becoming numbers. Numeric collection conversion should use the same element conversion behavior it already uses for other non-numeric values. The actual boolean getter, valid integers/floats, integer-to-float conversion, and inferred boolean collections should remain unchanged.

This is not a request to redesign primitive collection nullability (#777), change public signatures, or change JSON writer behavior.

Environment and validation

  • Current main: ee58dcf.
  • Python 3.14.5, Windows; editable local JSON/abstractions packages.
  • Added scalar, real JSON factory/child, and typed collection regressions: 12 failures on unchanged source; focused run also has 20 passing controls/existing tests.
  • No production traffic or external API credentials involved.

Discovered through source review and reproduced locally with AI assistance. I can provide the focused parser fix and regression tests.

Ngôn ngữ chính
Python
Star
31
Fork
48
Merge trung bình
16 giờ 36 phút
Pull request đã merge (30 ngày)
73

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 microsoft/kiota-python

Tất cả issue của microsoft/kiota-python

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.