Skip to content

Commit

Permalink
Fix error when users.table does not exist yet during initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Nov 22, 2024
1 parent 0d02e4c commit f1f9552
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/olympia/amo/management/commands/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.conf import settings
from django.core.management import call_command

from olympia.users.models import UserProfile

from .. import BaseDataCommand


Expand All @@ -25,9 +27,11 @@ def add_arguments(self, parser):
)

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):
"""
Expand Down
10 changes: 10 additions & 0 deletions src/olympia/amo/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ def test_handle_migration_failure(self):
],
)

@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):
Expand Down

0 comments on commit f1f9552

Please sign in to comment.