Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

email.utils.parsedate() and email.utils.parsedate_tz() should return None when date cannot be parsed #60129

Closed
Arfrever mannequin opened this issue Sep 12, 2012 · 9 comments
Assignees
Labels
release-blocker topic-email type-bug An unexpected behavior, bug, or error

Comments

@Arfrever
Copy link
Mannequin

Arfrever mannequin commented Sep 12, 2012

BPO 15925
Nosy @warsaw, @birkenfeld, @bitdancer
Files
  • parsedate_invalid.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2012-09-22.15:35:54.351>
    created_at = <Date 2012-09-12.00:37:45.217>
    labels = ['type-bug', 'expert-email', 'release-blocker']
    title = 'email.utils.parsedate() and email.utils.parsedate_tz() should return None when date cannot be parsed'
    updated_at = <Date 2012-09-24.05:46:47.118>
    user = 'https://bugs.python.org/Arfrever'

    bugs.python.org fields:

    activity = <Date 2012-09-24.05:46:47.118>
    actor = 'python-dev'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2012-09-22.15:35:54.351>
    closer = 'georg.brandl'
    components = ['email']
    creation = <Date 2012-09-12.00:37:45.217>
    creator = 'Arfrever'
    dependencies = []
    files = ['27205']
    hgrepos = []
    issue_num = 15925
    keywords = ['patch', '3.3regression']
    message_count = 9.0
    messages = ['170347', '170556', '170557', '170558', '170626', '170996', '170997', '171002', '171096']
    nosy_count = 5.0
    nosy_names = ['barry', 'georg.brandl', 'Arfrever', 'r.david.murray', 'python-dev']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue15925'
    versions = ['Python 3.3']

    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Sep 12, 2012

    Documentation (in Python 3.3) says that None is returned when date cannot be parsed.

    In Python 3.2:

    >> email.utils.parsedate("0")
    >> email.utils.parsedate_tz("0")
    >>

    In Python 3.3:

    >>> email.utils.parsedate("0")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python3.3/email/utils.py", line 232, in parsedate
        return _parsedate(data)
      File "/usr/lib64/python3.3/email/_parseaddr.py", line 172, in parsedate
        t = parsedate_tz(data)
      File "/usr/lib64/python3.3/email/_parseaddr.py", line 51, in parsedate_tz
        if res[9] is None:
    TypeError: 'NoneType' object is not subscriptable
    >>> email.utils.parsedate_tz("0")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python3.3/email/utils.py", line 238, in parsedate_tz
        return _parsedate_tz(data)
      File "/usr/lib64/python3.3/email/_parseaddr.py", line 51, in parsedate_tz
        if res[9] is None:
    TypeError: 'NoneType' object is not subscriptable
    >>> email.utils.parsedate_to_datetime("0")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python3.3/email/utils.py", line 243, in parsedate_to_datetime
        *dtuple, tz = __parsedate_tz(data)
    TypeError: 'NoneType' object is not iterable
    >>>

    @bitdancer
    Copy link
    Member

    Here is a patch.

    Georg, this unfortunately represents a regression from 3.2 and should be fixed.

    @bitdancer
    Copy link
    Member

    Hmm. Not sure why Georg didn't get auto-added.

    @bitdancer
    Copy link
    Member

    Oh, and I'm purposely allowing parsedate_to_datetime throw exceptions. I suppose that should be documented, but that's a separate issue.

    @bitdancer bitdancer changed the title email.utils.parsedate(), email.utils.parsedate_tz() and email.utils.parsedate_to_datetime() should return None when date cannot be parsed email.utils.parsedate() and email.utils.parsedate_tz() should return None when date cannot be parsed Sep 16, 2012
    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Sep 17, 2012

    I think that email.utils.parsedate_to_datetime("0") should raise ValueError instead of TypeError.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 22, 2012

    New changeset 3b03d31f6a79 by R David Murray in branch 'default':
    bpo-15925: fix regression: return None for null and non-date strings.
    http://hg.python.org/cpython/rev/3b03d31f6a79

    @bitdancer
    Copy link
    Member

    I don't think it is worth the extra code to convert the TypeError into a ValueError. We aren't very strict about the distinction between those two.

    Leaving this open for Georg to transplant it to 3.3.0.

    @bitdancer bitdancer added the type-bug An unexpected behavior, bug, or error label Sep 22, 2012
    @birkenfeld
    Copy link
    Member

    This was committed to the release clone as c1e9a1fc6931.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 24, 2012

    New changeset c1e9a1fc6931 by Georg Brandl in branch 'default':
    Closes bpo-15925: fix regression in parsedate() and parsedate_tz() that should return None if unable to parse the argument.
    http://hg.python.org/cpython/rev/c1e9a1fc6931

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    release-blocker topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants