Skip to content

Commit

Permalink
we should probably not raise an error, but rather log an error on exp…
Browse files Browse the repository at this point in the history
…ansion failures - also added reference to the github issue. Updates #157
  • Loading branch information
tobixen committed May 8, 2022
1 parent c20ed6a commit ddcd115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,9 @@ def build_date_search_query(self, start, end=None, compfilter="VEVENT", expand="
root = cdav.CalendarQuery() + [prop, filter]
return root

def date_search(self, start, end=None, compfilter="VEVENT", expand="maybe"):
def date_search(self, start, end=None, compfilter="VEVENT", expand="maybe", verify_expand=False):
# type (TimeStamp, TimeStamp, str, str) -> CalendarObjectResource
"""
Search events by date in the calendar. Recurring events are
"""Search events by date in the calendar. Recurring events are
expanded if they are occuring during the specified time frame
and if an end timestamp is given.
Expand All @@ -717,6 +716,11 @@ def date_search(self, start, end=None, compfilter="VEVENT", expand="maybe"):
* expand - should recurrent events be expanded? (to preserve
backward-compatibility the default "maybe" will be changed into True
unless the date_search is open-ended)
* verify_expand - quite some servers does not support
expansion. If verify_expand is set to True, an error will
be raised if expansion is requested but the server does not
support expansion. Defaults to False for
backward-compatibility.
Returns:
* [CalendarObjectResource(), ...]
Expand Down Expand Up @@ -745,12 +749,15 @@ def date_search(self, start, end=None, compfilter="VEVENT", expand="maybe"):
objects = self.search(root, comp_class)
if expand:
for o in objects:
components = o.instance.components()
components = o.vobject_instance.components()
for i in components:
if i.name == 'VEVENT':
recurrance_properties = ['exdate', 'exrule', 'rdate', 'rrule']
if any(key in recurrance_properties for key in i.contents):
raise error.ReportError('CalDAV server did not expand vevents as requested.')
if verify_expansion:
raise error.ReportError('CalDAV server did not expand recurring vevents as requested. See https://github.com/python-caldav/caldav/issues/157')
else:
logging.error('CalDAV server does not support recurring events properly. See https://github.com/python-caldav/caldav/issues/157')
return objects

def _request_report_build_resultlist(self, xml, comp_class=None, props=None, no_calendardata=False):
Expand Down
2 changes: 1 addition & 1 deletion tests/compatibility_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
]

nextcloud = [
'no_sync_token',
'sync_breaks_on_delete',
'no_recurring_todo',
'no_recurring_todo_expand',
]
Expand Down

0 comments on commit ddcd115

Please sign in to comment.