Fix error when users.table does not exist yet during initialize

This commit is contained in:
Kevin Meinhardt 2024-11-22 20:17:51 +01:00
Родитель 0d02e4cbba
Коммит f1f95521c7
2 изменённых файлов: 17 добавлений и 3 удалений

Просмотреть файл

@ -3,6 +3,8 @@ import logging
from django.conf import settings
from django.core.management import call_command
from olympia.users.models import UserProfile
from .. import BaseDataCommand
@ -25,9 +27,11 @@ class Command(BaseDataCommand):
)
def local_admin_exists(self):
from olympia.users.models import UserProfile
return UserProfile.objects.filter(email=settings.LOCAL_ADMIN_EMAIL).exists()
try:
return UserProfile.objects.filter(email=settings.LOCAL_ADMIN_EMAIL).exists()
except Exception as e:
logging.error(f'Error checking if local admin exists: {e}')
return False
def handle(self, *args, **options):
"""

Просмотреть файл

@ -350,6 +350,16 @@ class TestInitializeDataCommand(BaseTestDataCommand):
],
)
@mock.patch('olympia.amo.management.commands.initialize.UserProfile.objects.filter')
def test_handle_mysql_exception(self, mock_filter):
mock_filter.return_value.exists.side_effect = Exception('test')
call_command('initialize')
self._assert_commands_called_in_order(
self.mocks['mock_call_command'],
[self.mock_commands.data_seed],
)
class TestBaseDataCommand(BaseTestDataCommand):
def setUp(self):