From 219071fbe74d613b910086b2c4e00480b4a79219 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Fri, 15 Mar 2024 08:48:35 -0700 Subject: [PATCH] Fix todo dtstart values for floating due dates (#313) * Fix for dtstart persisted with an invalid timezone * Remove comments * Entirely remove invalid dtstart values * Bump to 7.0.3 * Address lint errors --- ical/todo.py | 29 ++----------------- setup.cfg | 2 +- tests/__snapshots__/test_calendar_stream.ambr | 26 ++++++++++++++--- tests/testdata/todo-invalid-dtstart-tzid.ics | 10 +++++++ 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/ical/todo.py b/ical/todo.py index 034650a..337fa8e 100644 --- a/ical/todo.py +++ b/ical/todo.py @@ -25,7 +25,7 @@ from .component import ComponentModel, validate_until_dtstart, validate_recurrence_dates from .exceptions import CalendarParseError from .iter import RulesetIterable -from .parsing.property import ParsedProperty, ParsedPropertyParameter +from .parsing.property import ParsedProperty from .timespan import Timespan from .types import ( CalAddress, @@ -37,7 +37,6 @@ RequestStatus, Uri, RelatedTo, - date_time, ) from .util import dtstamp_factory, normalize_datetime, uid_factory, local_timezone @@ -376,35 +375,13 @@ def _parse_single_property(cls, field_type: type, prop: ParsedProperty) -> Any: and field_type == datetime.datetime and prop.params is not None ): - new_prop = ParsedProperty( - prop.name, prop.value, _repair_tzid_param(prop.params) - ) _LOGGER.debug( - "Applying todo dtstart repair for invalid timezone: %s", new_prop + "Applying todo dtstart repair for invalid timezone; Removing dtstart", ) - try: - return date_time.parse_property_value(new_prop) - except ValueError as repair_err: - _LOGGER.debug( - "To-do dtstart repair failed %s, raising original error", - repair_err, - ) + return None raise err _validate_until_dtstart = root_validator(allow_reuse=True)(validate_until_dtstart) _validate_recurrence_dates = root_validator(allow_reuse=True)( validate_recurrence_dates ) - - -def _repair_tzid_param( - params: list[ParsedPropertyParameter], -) -> list[ParsedPropertyParameter]: - """Repair the TZID parameter.""" - result_params = [] - for param in params: - if param.name == "TZID": - result_params.append(ParsedPropertyParameter(param.name, ["UTC"])) - continue - result_params.append(param) - return result_params diff --git a/setup.cfg b/setup.cfg index ce76eac..5b782eb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ical -version = 7.0.2 +version = 7.0.3 description = Python iCalendar implementation (rfc 2445) long_description = file: README.md long_description_content_type = text/markdown diff --git a/tests/__snapshots__/test_calendar_stream.ambr b/tests/__snapshots__/test_calendar_stream.ambr index 85704ef..60121c8 100644 --- a/tests/__snapshots__/test_calendar_stream.ambr +++ b/tests/__snapshots__/test_calendar_stream.ambr @@ -1101,7 +1101,6 @@ ]), 'classification': 'CONFIDENTIAL', 'dtstamp': '2007-03-13T12:34:32+00:00', - 'dtstart': '2007-05-01T11:00:00+00:00', 'due': '2007-05-01T11:00:00-07:00', 'status': 'NEEDS-ACTION', 'summary': 'Submit Quebec Income Tax Return for 2006', @@ -1110,13 +1109,24 @@ dict({ 'completed': '2007-07-07T10:00:00+00:00', 'dtstamp': '2007-05-14T10:32:11+00:00', - 'dtstart': '2007-05-14T11:00:00+00:00', 'due': '2007-07-09T13:00:00+00:00', 'priority': 1, 'status': 'NEEDS-ACTION', 'summary': 'Submit Revised Internet-Draft', 'uid': '20070514T103211Z-123404@example.com', }), + dict({ + 'categories': list([ + 'FAMILY', + 'FINANCE', + ]), + 'classification': 'CONFIDENTIAL', + 'dtstamp': '2007-03-13T12:34:32+00:00', + 'due': '2007-05-01T11:00:00', + 'status': 'NEEDS-ACTION', + 'summary': 'Floating due datetime', + 'uid': '20070313T123432Z-456553@example.com', + }), ]), 'version': '2.0', }), @@ -1845,7 +1855,6 @@ CATEGORIES:FAMILY CATEGORIES:FINANCE CLASS:CONFIDENTIAL - DTSTART:20070501T110000Z DUE;TZID=America/Los_Angeles:20070501T110000 STATUS:NEEDS-ACTION SUMMARY:Submit Quebec Income Tax Return for 2006 @@ -1854,12 +1863,21 @@ DTSTAMP:20070514T103211Z UID:20070514T103211Z-123404@example.com COMPLETED:20070707T100000Z - DTSTART:20070514T110000Z DUE:20070709T130000Z PRIORITY:1 STATUS:NEEDS-ACTION SUMMARY:Submit Revised Internet-Draft END:VTODO + BEGIN:VTODO + DTSTAMP:20070313T123432Z + UID:20070313T123432Z-456553@example.com + CATEGORIES:FAMILY + CATEGORIES:FINANCE + CLASS:CONFIDENTIAL + DUE:20070501T110000 + STATUS:NEEDS-ACTION + SUMMARY:Floating due datetime + END:VTODO END:VCALENDAR ''' # --- diff --git a/tests/testdata/todo-invalid-dtstart-tzid.ics b/tests/testdata/todo-invalid-dtstart-tzid.ics index a0973ee..e28d312 100644 --- a/tests/testdata/todo-invalid-dtstart-tzid.ics +++ b/tests/testdata/todo-invalid-dtstart-tzid.ics @@ -21,4 +21,14 @@ COMPLETED:20070707T100000Z PRIORITY:1 STATUS:NEEDS-ACTION END:VTODO +BEGIN:VTODO +UID:20070313T123432Z-456553@example.com +DTSTAMP:20070313T123432Z +SUMMARY:Floating due datetime +DTSTART;TZID=CST:20070501T110000 +DUE:20070501T110000 +CLASS:CONFIDENTIAL +CATEGORIES:FAMILY,FINANCE +STATUS:NEEDS-ACTION +END:VTODO END:VCALENDAR