Skip to content
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
1 change: 1 addition & 0 deletions CHANGES/+fix_post_migrate_hooks.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed post-migrate hooks to prevent failing on incomplete or rolled back migrations.
49 changes: 27 additions & 22 deletions pulpcore/app/apps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import random
from collections import defaultdict
from contextlib import suppress
from gettext import gettext as _
from importlib import import_module

from django import apps
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import connection, transaction
from django.db import ProgrammingError, connection, transaction
from django.db.models.signals import post_migrate, pre_migrate
from django.utils.module_loading import module_has_submodule

Expand Down Expand Up @@ -320,27 +321,31 @@ def _populate_access_policies(sender, apps, verbosity, **kwargs):


def _populate_system_id(sender, apps, verbosity, **kwargs):
SystemID = apps.get_model("core", "SystemID")
if not SystemID.objects.exists():
SystemID().save()


def _ensure_default_domain(sender, **kwargs):
table_names = connection.introspection.table_names()
if "core_domain" in table_names:
from pulpcore.app.util import get_default_domain

default = get_default_domain() # Cache the default domain
# Match the Pulp settings
if (
settings.HIDE_GUARDED_DISTRIBUTIONS != default.hide_guarded_distributions
or settings.REDIRECT_TO_OBJECT_STORAGE != default.redirect_to_object_storage
or settings.STORAGES["default"]["BACKEND"] != default.storage_class
):
default.hide_guarded_distributions = settings.HIDE_GUARDED_DISTRIBUTIONS
default.redirect_to_object_storage = settings.REDIRECT_TO_OBJECT_STORAGE
default.storage_class = settings.STORAGES["default"]["BACKEND"]
default.save(skip_hooks=True)
with suppress(LookupError):
SystemID = apps.get_model("core", "SystemID")
if not SystemID.objects.exists():
SystemID().save()


def _ensure_default_domain(sender, apps, **kwargs):
# This is a post migrate hook.
# But on rolling back the database may not match what this function expects.
with suppress(LookupError, ProgrammingError):
table_names = connection.introspection.table_names()
if "core_domain" in table_names:
from pulpcore.app.util import get_default_domain

default = get_default_domain() # Cache the default domain
# Match the Pulp settings
if (
settings.HIDE_GUARDED_DISTRIBUTIONS != default.hide_guarded_distributions
or settings.REDIRECT_TO_OBJECT_STORAGE != default.redirect_to_object_storage
or settings.STORAGES["default"]["BACKEND"] != default.storage_class
):
default.hide_guarded_distributions = settings.HIDE_GUARDED_DISTRIBUTIONS
default.redirect_to_object_storage = settings.REDIRECT_TO_OBJECT_STORAGE
default.storage_class = settings.STORAGES["default"]["BACKEND"]
default.save(skip_hooks=True)


def _populate_roles(sender, apps, verbosity, **kwargs):
Expand Down
Loading