Search code examples
exchangelib

exchangelib consistently returns 'QuerySet' object has no attribute 'iterator' when using chunkify


Problem: When using exchangelib for large amounts of emails(in this case 10K+) the entire set is attempted to be loaded. I have tried to employ chunkify:

from exchangelib import Credentials, Account

for item in account.inbox\
        .filter(is_read=False, sender__contains='gmail')\
        .only('is_read', 'subject', 'body') \
        .order_by('-datetime_received')\
        .iterator():
    print('Email subject is:', item.subject)
    print('Email is from:', item.sender)

Which yields the following log error:

    for item in account.inbox.filter(is_read=False, sender__contains='gmail').only('is_read', 'subject', 'body').order_by('-datetime_received').iterator():
AttributeError: 'QuerySet' object has no attribute 'iterator'

Solution

  • The .iterator() method was deprecated in exchangelib v4.0.0 and finally removed in v4.7.0. exchangelib no longer does any internal caching so the method is a no-op.