Skip to content

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

Description

@Arfrever
mannequin
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']

    Activity

    1. Arfrever commented on Sep 12, 2012

      Arfrevermannequin
      MannequinAuthor

      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
      >>>
    2. bitdancer commented on Sep 16, 2012

      @bitdancer
      Member

      Here is a patch.

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

    3. bitdancer commented on Sep 16, 2012

      @bitdancer
      Member

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

    4. bitdancer commented on Sep 16, 2012

      @bitdancer
      Member

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

    5. 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[/+] on Sep 16, 2012
    6. Arfrever commented on Sep 17, 2012

      Arfrevermannequin
      MannequinAuthor

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

    7. python-dev commented on Sep 22, 2012

      python-devmannequin
      Mannequin

      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

    8. bitdancer commented on Sep 22, 2012

      @bitdancer
      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.

    9. birkenfeld commented on Sep 22, 2012

      @birkenfeld
      Member

      This was committed to the release clone as c1e9a1fc6931.

    10. python-dev commented on Sep 24, 2012

      python-devmannequin
      Mannequin

      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

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions