Skip to content

convert_date raises raw TypeError for incomplete values instead of returning them as str #1286

Open

Description

@rahul05ranjan

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):

from pymysql.converters import convert_date, convert_datetime

convert_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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions