0

My problem looks weird. Exchange 2010 SP1. Code looks for conflicting record in Room Calendar and suposed to delete it. Code looks like:

#DELEGATE also doesn't work
 roomAccount = Account(primary_smtp_address=room_mailbox, config=config,
                              autodiscover=False, access_type=IMPERSONATION)
 items = roomAccount.calendar.filter(start__gt=now_with_past) 
 for item in items:
     if (start_dt_ews != start_dt_remote or item.subject != remote_record_subject or duration != remote_record_duration):
                            has_conflicts = detect_conflicts(roomAccount, item)
                            if has_conflicts:                            
                                process_conflict(item, 'update_conflict')
                                remove_meeting_data(item, item.organizer)
                                continue                                

def detect_conflicts(roomAccount, item):
    try:
        has_conflicts = False
        if item.conflicting_meeting_count > 0:
            if item.start_dt != item.start:
                has_conflicts = True
        return has_conflicts
    except Exception as e:
        trace_back = traceback.format_exc()
        log_str = "Error in process_service " + str(e) + " " + str(trace_back)
        Logger.error(log_str)
        return False    

def process_conflict(item, category):
    if item.recurrence:
        conflict_notify_and_delete(item, category, True)
    else:
        conflict_notify_and_delete(item, category, False)
        Logger.error(item.subject + " meeting conflict error.")     
        
def conflict_notify_and_delete(item, category, serial):
    send_email(item.organizer, category, (item.subject))
    try:
        if serial:
            item.delete(affected_task_occurrences=ALL_OCCURRENCIES)
            item.save()
        else:               
            # doesn't  work
            item.delete(send_meeting_cancellations=SEND_TO_NONE, 
 affected_task_occurrences=ALL_OCCURRENCIES)            
            # or also doesn't  work
            item.delete()           
            # or raise trash folder absense error.
            item.move_to_trash()

            # or raise trash folder absense error again.
            item.soft_delete()
            
            #abrakadabra atempts with rescheduling and subsequent deletion raise
            # "Set action is invalid for property. (field: FieldURI(field_uri='calendar:StartTimeZone'))"  error            
            item.start = UTC_NOW() + timedelta(days=6000)
            item.save(update_fields=['start'])
            item.delete()

The strangest fact about all this - any of delete() processing simply silent - no errors, no exceptions, everything looks like to be just fine while actually nothing is deleted of modified.. Second strangest fact - sometimes but not every time i'm trying to item.save() after item.delete() , it raise " AttributeError("Folder must be supplied when in save-only mode")", but item may be deleted at once. And may be not :(( This weird things happen only in part of code that process conflicting calendar items. Notconflicting items processing is fine - deleting and modifiying are ok.

Does anybody has any idea, what is going on and how to finally delete conflicting record from Room calendar without canceling a meeting from organizers's calendar - we do not want user to loose his item and information inside it? I've tried to google EWS setiings that can cause such weirdness but with no luck :(

Dadudki
  • 37
  • 4
  • If a delete fails, that should raise an error in EWS. I don't know why that's not happening here, but exchangelib assumes the item is deleted if it doesn't get an error message. That's why you get an error calling.save() after .delete() - exchangelib doesn't allow saving an item it thinks is deleted. – Erik Cederstrand Dec 11 '20 at 10:30
  • Yes, Erik, that's true. I'm using save() sometimes because, yes i know how stupid this looks, but sometimes(!) after this error being raised the item is actually deleted. That's another abrakadabra. Simple delete() doesn't leads to actual deletion at all. – Dadudki Dec 11 '20 at 12:57

0 Answers0