Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The localized fix correctly handles negative durations, with focused regression coverage and no unresolved findings.
No open issues 🎉
What changed in this PR
Corrects MySQL parameter encoding for negative timedelta values by formatting the absolute duration and applying the sign once.
Changes:
- Preserves negative duration magnitudes without changing positive or zero formatting.
- Adds offline cursor
mogrify()regressions and converter round-trip assertions for signed durations.
| File | Description |
|---|---|
singlestoredb/tests/test_timedelta_parameters.py |
Adds negative-duration regressions and positive/zero controls. |
singlestoredb/mysql/converters.py |
Separates the duration’s sign from its magnitude during encoding. |
Review effort: Balanced
|
Nice catch. This looks like we inherited this issue from the original PyMySQL code. There is another copy of that converter in |
|
Thanks, good catch. |
kesmit13
left a comment
There was a problem hiding this comment.
I think it would be better to name the new test file test_parameters.py. That way if we need to add tests for other parameter types, the filename won't be so specific. Other than that, I can approve. It's still marked as a draft though. Not sure if there is a reason for that.
|
Renamed to |
329b748 to
e32e0ef
Compare
Problem
The MySQL parameter encoder combines normalized
timedelta.days(negative) with the nonnegativesecondsandmicrosecondsfields. This changes negative durations when formatting SQL parameters:A negative microsecond similarly becomes
'-1:59:59.999999'instead of'-00:00:00.000001'.Change
Format the absolute duration and attach its sign once, preserving the existing positive/zero formatting. Add offline public cursor
mogrify()regressions and converter round-trip assertions for negative subsecond, second, minute, hour, multi-day, fractional values, and positive/zero controls.Validation
SINGLESTOREDB_PURE_PYTHON=1mode.git diff --checkpasses.Python 3.12, editable SDK. These tests use deferred connections and never connect to a server. The full MySQL/HTTP protocol suites, accelerated binding path, and management/cloud tests were not run. An exploratory doctest run of unchanged
singlestoredb.convertershad two existing examples expecting printedNone(Python prints nothing for that return value); its other 11 examples passed. No unrelated docstring changes included.Note
Low Risk
Scoped change to timedelta parameter formatting with regression tests; fixes incorrect literals rather than altering unrelated binding behavior.
Overview
Fixes incorrect TIME literals when binding negative
datetime.timedeltavalues. The encoder previously mixed negativedayswith nonnegativeseconds/microseconds, producing wrong strings (e.g.-1:59:59instead of-00:00:01).MySQL (
escape_timedelta) and HTTP (encode_timedelta) now take the absolute duration, format hours/minutes/seconds as before, and prepend a single-whendays < 0. Positive and zero durations are unchanged.Adds offline tests that assert
cursor.mogrify()andencode_timedelta()match expected literals and round-trip throughtimedelta_fromisoformat.Reviewed by Cursor Bugbot for commit e32e0ef. Bugbot is set up for automated code reviews on this repo. Configure here.