Skip to content

parse_quantity raises decimal.Overflow instead of ValueError for some large quantities #2735

Closed

Description

@jbrown9513

What happened (please include outputs or screenshots):

While testing an experimental version of Perch, we found the following and figured it was worth a report.

parse_quantity raises ValueError for malformed quantities, but a quantity whose exponent overflows the decimal context escapes as decimal.Overflow:

from kubernetes.utils.quantity import parse_quantity

parse_quantity("abc")
# ValueError: Invalid number format: abc

parse_quantity("2.e388635141Ki")
# decimal.Overflow: [<class 'decimal.Overflow'>]

What you expected to happen:

A ValueError, like other quantities it can't handle, so callers that catch ValueError around it keep working.

How to reproduce it (as minimally and precisely as possible):

Run the snippet above against master. No cluster is needed.

Anything else we need to know?:

It's raised at kubernetes/utils/quantity.py:85, return number * (base ** exponent). The API server won't produce a quantity this large, so in practice it shows up with hand-written or third-party manifests. Catching decimal.DecimalException there and raising ValueError would keep the error type consistent.

Environment:

  • Kubernetes version (kubectl version): not needed, no cluster involved
  • OS (e.g., MacOS 10.13.6): macOS 26.2 (arm64)
  • Python version (python --version): 3.14.2
  • Python client version (pip list | grep kubernetes): 37.0.0+snapshot (master, bb9199f)

Activity

  1. yliaog commented on Oct 12, 2026

    @yliaog
    Contributor

    /help

  2. kubernetes-prow commented on Oct 12, 2026

    @kubernetes-prow
    Contributor

    @yliaog:
    This request has been marked as needing help from a contributor.

    Guidelines

    Please ensure that the issue body includes answers to the following questions:

    • Why are we solving this issue?
    • To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points?
    • How can the assignee reach out to you for help?

    For more details on the requirements of such an issue, please see here and ensure that they are met.

    If this request no longer meets these requirements, the label can be removed
    by commenting with the /remove-help command.

    Details

    In response to this:

    /help

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

  3. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions