Skip to content

Fix parse_date raising TypeError for dates without a time or seconds - #2245

Open
aad1tyaaaaa wants to merge 2 commits into
apache:trunkfrom
aad1tyaaaaa:fix-parse-date-partial
Open

aad1tyaaaaa wants to merge 2 commits into
apache:trunkfrom
aad1tyaaaaa:fix-parse-date-partial

Conversation

@aad1tyaaaaa

Copy link
Copy Markdown

Fix parse_date raising TypeError for dates without a time or seconds

Description

libcloud.utils.iso8601.parse_date raises TypeError instead of parsing valid ISO 8601 strings that leave out the time or the seconds:

>>> from libcloud.utils.iso8601 import parse_date
>>> parse_date("2020-01-01")
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
>>> parse_date("2020-01-01T10:20Z")
TypeError: ...

ISO8601_REGEX makes everything after the year optional, so these strings match, but the missing groups are None and go straight into int(). Upstream pyiso8601, which this module comes from, defaults them (month and day to 1, the time fields to 0); this change does the same. Strings with every field parse exactly as before.

This is independent of #2243 (fractional seconds), and the two branches merge cleanly.

Status

  • done, ready for review

Checklist

  • Code linting (black, isort)
  • Documentation (CHANGES.rst entry)
  • Tests: new test_parse_date_without_time_or_seconds in libcloud/test/test_utils.py (2020-01-01, 2020-01-01T10:20Z, 2020-01-01T10:20+02:00) fails on trunk and passes with this change; the compute, common and backup test suites pass.
  • ICLA not required for this small change

I used an AI assistant (Claude Code) to help find this bug and write the fix and test. I reviewed and ran everything myself.

The regex makes everything after the year optional, but the missing groups
were passed to int() as None. Default them like upstream pyiso8601 does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant