Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading