@@ -430,10 +430,8 @@ def test_imap_message_deduplication(
430430 )
431431
432432
433- @pytest .mark .usefixtures ("blockstore_backend" )
434- @pytest .mark .parametrize ("blockstore_backend" , ["disk" , "s3" ], indirect = True )
435433def test_gmail_handle_uidinvalid (
436- db , default_account , all_mail_folder , mock_imapclient , monkeypatch
434+ db , default_account , all_mail_folder , mock_imapclient , label
437435) -> None :
438436 """
439437 Tests when a GMail account's UID validity changes. In this case we attempt
@@ -466,20 +464,15 @@ def test_gmail_handle_uidinvalid(
466464 )
467465 folder_sync_engine .initial_sync ()
468466
469- # Add labels to some ImapUids to trigger the cascade loading issue
470- from inbox .models .label import Label
471-
472- # Create a label
473- label = Label .find_or_create (db .session , default_account , "Important" )
474-
475- # Get some ImapUids and add labels to them
467+ # We need to add labels to our imap uids so that the cascade delete on
468+ # LabelItems is required. This would trigger a deletion during the yield_chunk
469+ # query if any ORM level cascades are triggered.
476470 imap_uids = (
477471 db .session .query (ImapUid )
478472 .filter (ImapUid .folder_id == all_mail_folder .id )
479473 .limit (5 )
480474 .all ()
481475 )
482-
483476 for uid in imap_uids :
484477 uid .labels .add (label )
485478
@@ -489,10 +482,10 @@ def test_gmail_handle_uidinvalid(
489482 with pytest .raises (UidInvalid ):
490483 folder_sync_engine .poll_impl ()
491484
492- # Call resync_uids_impl directly with chunk_size=1 to trigger the issue
485+ # chunk_size must be set small (default is 1000) so that we actually have
486+ # more than one chunk, keeping the query open.
493487 folder_sync_engine .resync_uids_impl (chunk_size = 1 )
494488
495- # No need to check new_state since we're calling impl directly
496489 assert (
497490 db .session .query (ImapUid )
498491 .filter (ImapUid .folder_id == all_mail_folder .id )
0 commit comments