Repository navigation
fix: raise ValueError for out-of-range integers in ULID.from_int - #81
Merged
Merged
Conversation
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.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Follow-up to the suggestion in #78.
ULID.from_int()passed anyinttoint.to_bytes(), soULID.from_int(-1)andULID.from_int(2**128)raised a bareOverflowError. It now checks the range and raisesValueError("Value is outside the 128-bit range of a ULID"), like the other constructors.Changes
ULID.from_int(): explicit range check, withRaisesdocumented in the docstringOverflowErrorulid.sqlalchemy: drop the now redundant range check in the value conversion0,2**128 - 1) and for out-of-range values (-1,2**128,2**129)Verification
uv run poe checkanduv run poe test(192 passed) pass locally.