Skip to content

Commit 55e18bc

Browse files
Fallback to uid when ical uid is none (#1072)
1 parent 38899a2 commit 55e18bc

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

inbox/events/microsoft/parse.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,13 @@ def synthesize_canceled_occurrence(
417417
+ "-synthesizedCancellation-"
418418
+ start_datetime.date().isoformat()
419419
)
420-
cancellation_ical_uid = (
421-
master_event["iCalUId"]
422-
+ "-synthesizedCancellation-"
423-
+ start_datetime.date().isoformat()
424-
)
420+
cancellation_ical_uid = None
421+
if master_event["iCalUId"] is not None:
422+
cancellation_ical_uid = (
423+
master_event["iCalUId"]
424+
+ "-synthesizedCancellation-"
425+
+ start_datetime.date().isoformat()
426+
)
425427
cancellation_start = dump_datetime_as_msgraph_datetime_tz(start_datetime)
426428
assert start_datetime.tzinfo == pytz.UTC
427429
original_start = start_datetime.replace(tzinfo=None).isoformat() + "Z"
@@ -769,6 +771,7 @@ def parse_event(
769771
uid=(
770772
ical_uid
771773
if created_date_time > config["MS_GRAPH_ICAL_UID_CUTOFF"]
774+
and ical_uid is not None
772775
else event_id
773776
),
774777
raw_data=raw_data,

tests/events/microsoft/test_parse.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,63 @@ def test_calculate_exception_and_canceled_occurrences_with_deletion_around_dst()
930930
)
931931

932932

933+
def test_calculate_exception_and_canceled_occurrences_with_null_ical_uid() -> (
934+
None
935+
):
936+
"""Test that synthesized cancellations work when master event has null iCalUId."""
937+
master_event_null_ical = {
938+
"id": "event-id-123",
939+
"iCalUId": None, # This can happen for events before the cutoff date
940+
"originalStartTimeZone": "Eastern Standard Time",
941+
"originalEndTimeZone": "Eastern Standard Time",
942+
"type": "seriesMaster",
943+
"subject": "Test Event",
944+
"start": {
945+
"dateTime": "2022-09-26T12:00:00.0000000",
946+
"timeZone": "UTC",
947+
},
948+
"end": {"dateTime": "2022-09-26T12:30:00.0000000", "timeZone": "UTC"},
949+
"recurrence": {
950+
"pattern": {
951+
"type": "daily",
952+
"interval": 1,
953+
"month": 0,
954+
"dayOfMonth": 0,
955+
"firstDayOfWeek": "sunday",
956+
"index": "first",
957+
},
958+
"range": {
959+
"type": "endDate",
960+
"startDate": "2022-09-26",
961+
"endDate": "2022-09-28",
962+
"recurrenceTimeZone": "Eastern Standard Time",
963+
"numberOfOccurrences": 0,
964+
},
965+
},
966+
}
967+
968+
occurrences = [
969+
{"originalStart": "2022-09-26T12:00:00Z", "type": "occurrence"},
970+
# Missing 2022-09-27
971+
{"originalStart": "2022-09-28T12:00:00Z", "type": "occurrence"},
972+
]
973+
974+
((), (cancellation,)) = calculate_exception_and_canceled_occurrences(
975+
master_event_null_ical,
976+
occurrences,
977+
datetime.datetime(2022, 9, 29, 23, 59, 59, tzinfo=pytz.UTC),
978+
)
979+
980+
assert cancellation["type"] == "synthesizedCancellation"
981+
assert (
982+
cancellation["iCalUId"] is None
983+
) # Should be None, not a concatenated string
984+
assert (
985+
cancellation["id"] == "event-id-123-synthesizedCancellation-2022-09-27"
986+
)
987+
assert cancellation["isCancelled"] is True
988+
989+
933990
master_with_exception = {
934991
"id": "AAMkADdiYzg5OGRlLTY1MjktNDc2Ni05YmVkLWMxMzFlNTQ0MzU3YQBGAAAAAACi9RQWB-SNTZBuALM6KIOsBwBtf4g8yY_zTZgZh6x0X-50AAIM02sjAABtf4g8yY_zTZgZh6x0X-50AAIQCYpPAAA=",
935992
"subject": "Expansion",

0 commit comments

Comments
 (0)