Skip to content

fix: raise ValueError for out-of-range integers in ULID.from_int - #81

Merged
mdomke merged 1 commit into
mainfrom
fix/from-int-range
Nov 17, 2026
Merged

mdomke merged 1 commit into
mainfrom
fix/from-int-range

Conversation

@mdomke

@mdomke mdomke commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Follow-up to the suggestion in #78.

ULID.from_int() passed any int to int.to_bytes(), so ULID.from_int(-1) and ULID.from_int(2**128) raised a bare OverflowError. It now checks the range and raises ValueError("Value is outside the 128-bit range of a ULID"), like the other constructors.

Changes

  • ULID.from_int(): explicit range check, with Raises documented in the docstring
  • Pydantic validation: no longer needs to catch OverflowError
  • ulid.sqlalchemy: drop the now redundant range check in the value conversion
  • Tests for both bounds (0, 2**128 - 1) and for out-of-range values (-1, 2**128, 2**129)
  • Changelog entry under Unreleased → Fixed

Verification

uv run poe check and uv run poe test (192 passed) pass locally.

ULID.from_int() passed any int to int.to_bytes(), so negative values and
values of 2**128 or more raised a bare OverflowError. Check the range
explicitly and raise ValueError, consistent with the other constructors.

The Pydantic validator no longer needs to catch OverflowError, and the
SQLAlchemy type no longer needs its own range check.
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.69%. Comparing base (aa949e4) to head (9133a85).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #81   +/-   ##
=======================================
  Coverage   98.69%   98.69%           
=======================================
  Files           5        5           
  Lines         460      460           
  Branches       82       82           
=======================================
  Hits          454      454           
  Misses          4        4           
  Partials        2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mdomke
mdomke merged commit 5a42522 into main Nov 17, 2026
13 checks passed
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.

1 participant