Repository navigation
fix: convert_date raises TypeError for incomplete values - #1292
rahul05ranjan wants to merge 1 commit into
Conversation
datetime.date(*...) is called with whatever int() accepts from the dash-separated components, so a value with fewer than three parts crashes with a raw TypeError (missing required argument 'day') instead of being returned as str like every other illegal value per the documented contract. convert_datetime reaches the same crash through its convert_date fallback, taking down result decoding. Check the component count up front and return the value as str, and pin the behavior in the converter doctests. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Hi! Friendly reminder — |
convert_dateandconvert_datetimedocument that illegal values are returned unchanged as a string, and the doctests pin that convention (convert_date('2007-02-31')→'2007-02-31',convert_datetime('0000-00-00 00:00:00')→ str). But a value with fewer than three--separated components passes theint()conversion and then failsdatetime.date()'s arity with a rawTypeError:Since both components
int()-parse cleanly, the incomplete value slips past theexcept ValueErrorthat implements the "illegal values are returned as str" contract. A result row containing such a string crashes inside result decoding instead of yielding the value.Fix: check the component count up front and return the value as str, consistent with every other input the date constructor cannot consume.
convert_datetimeis covered through itsconvert_datefallback. Doctest lines pinningconvert_date('2007-02')andconvert_datetime('2007-02')→'2007-02'are added to the converter docstrings.Verification (system Python 3.13, no server needed — the converter path is pure decoding):
pytest --doctest-modules pymysql/converters.py: 4 passed (13 doctest asserts) with the change; on unpatchedmain@7b9584fthe repro crashes with the rawTypeErrorabove.'2007-02'→'2007-02'(both converters),'2007-02-31'→ unchanged,'2007-02-26'→date(2007, 2, 26), bytes inputb'2007-02'→'2007-02', valid datetimes unchanged.pytest --doctest-modules pymysql/converters.py).Summary by CodeRabbit
"2007-02", are now returned unchanged instead of causing an error.