diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 727ba7b4a6..4999deef98 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -6,6 +6,7 @@ import shutil from mimetypes import guess_type from typing import Any, Dict, Iterable, List, Optional, Tuple +import bmemcached import orjson from bs4 import BeautifulSoup from django.conf import settings @@ -876,7 +877,9 @@ def import_uploads( process_avatars(record) else: connection.close() - cache._cache.disconnect_all() + _cache = getattr(cache, "_cache") + assert isinstance(_cache, bmemcached.Client) + _cache.disconnect_all() with multiprocessing.Pool(processes) as p: for out in p.imap_unordered(process_avatars, records): pass diff --git a/zerver/lib/transfer.py b/zerver/lib/transfer.py index 1e16c2e4cb..6fde8d95da 100644 --- a/zerver/lib/transfer.py +++ b/zerver/lib/transfer.py @@ -3,6 +3,7 @@ import multiprocessing import os from mimetypes import guess_type +import bmemcached from django.conf import settings from django.core.cache import cache from django.db import connection @@ -40,7 +41,9 @@ def transfer_avatars_to_s3(processes: int) -> None: _transfer_avatar_to_s3(user) else: # nocoverage connection.close() - cache._cache.disconnect_all() + _cache = getattr(cache, "_cache") + assert isinstance(_cache, bmemcached.Client) + _cache.disconnect_all() with multiprocessing.Pool(processes) as p: for out in p.imap_unordered(_transfer_avatar_to_s3, users): pass @@ -71,7 +74,9 @@ def transfer_message_files_to_s3(processes: int) -> None: _transfer_message_files_to_s3(attachment) else: # nocoverage connection.close() - cache._cache.disconnect_all() + _cache = getattr(cache, "_cache") + assert isinstance(_cache, bmemcached.Client) + _cache.disconnect_all() with multiprocessing.Pool(processes) as p: for out in p.imap_unordered(_transfer_message_files_to_s3, attachments): pass @@ -101,7 +106,9 @@ def transfer_emoji_to_s3(processes: int) -> None: _transfer_emoji_to_s3(realm_emoji) else: # nocoverage connection.close() - cache._cache.disconnect_all() + _cache = getattr(cache, "_cache") + assert isinstance(_cache, bmemcached.Client) + _cache.disconnect_all() with multiprocessing.Pool(processes) as p: for out in p.imap_unordered(_transfer_emoji_to_s3, realm_emojis): pass diff --git a/zilencer/management/commands/mark_all_messages_unread.py b/zilencer/management/commands/mark_all_messages_unread.py index 945c743324..2b5a5c5d9d 100644 --- a/zilencer/management/commands/mark_all_messages_unread.py +++ b/zilencer/management/commands/mark_all_messages_unread.py @@ -1,5 +1,6 @@ from typing import Any +import bmemcached from django.conf import settings from django.core.cache import cache from django.core.management.base import BaseCommand @@ -14,4 +15,6 @@ class Command(BaseCommand): def handle(self, *args: Any, **options: Any) -> None: assert settings.DEVELOPMENT UserMessage.objects.all().update(flags=F("flags").bitand(~UserMessage.flags.read)) - cache._cache.flush_all() + _cache = getattr(cache, "_cache") + assert isinstance(_cache, bmemcached.Client) + _cache.flush_all()