Fix error when users.table does not exist yet during initialize
This commit is contained in:
Родитель
0d02e4cbba
Коммит
f1f95521c7
|
@ -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):
|
||||
|
|
Загрузка…
Ссылка в новой задаче