You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
convert_date raises raw TypeError for incomplete values instead of returning them as str #1286
convert_date raises raw TypeError for incomplete values, violating its documented "illegal values are returned as str" contract
Repro (PyMySQL 1.5.x, current main):
frompymysql.convertersimportconvert_date, convert_datetimeconvert_date('2007-02') # TypeError: function missing required argument 'day' (pos 3)convert_datetime('2007-02') # TypeError: function missing required argument 'day' (pos 3)
The docstrings and doctests of the converters document that illegal values are returned unchanged as a string (convert_date('2007-02-31') → '2007-02-31', convert_datetime('0000-00-00 00:00:00') → str), and every other malformed input follows that contract. But a value with fewer than three --separated components passes the int() conversion and then fails datetime.date()'s arity with a raw TypeError:
TypeError: function missing required argument 'day' (pos 3)
convert_datetime reaches the same crash through its except ValueError: return convert_date(obj) fallback (the fallback itself raises). A result row containing such a string (e.g. a server returning a partial/zero date, or a user mapping the DATE converter onto a TEXT column) crashes inside result decoding instead of yielding the value.
Expected
convert_date('2007-02') → '2007-02', consistent with every other illegal value, per the module's own doctest convention (# Run doctests with pytest --doctest-modules pymysql/converters.py).
Happy to send a PR — it's a one-line fix plus a doctest.
Activity