mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
correctly cascade set null
* It's problematic to delete an instance that is referenced by a foreign key; where the referening model is one that has a Polymorphic parent. * Specifically, when Django goes to nullify the relationship it relies on the related instances[0] class type to issue a query to decide what to nullify. So if the foreignkey references multiple different types (i.e. ProjectUpdate, Job) then only 1 of those class types will get nullified. The end result is an IntegrityError when delete() is called. * This changeset ensures that the parent Polymorphic class is queried so that all the foreignkey entries are nullified * Also remove old Django "hack" that doesn't work with Django 1.11
This commit is contained in:
@@ -38,6 +38,7 @@ from awx.main.utils import (
|
||||
copy_model_by_class, copy_m2m_relationships,
|
||||
get_type_for_model, parse_yaml_or_json
|
||||
)
|
||||
from awx.main.utils import polymorphic
|
||||
from awx.main.constants import ACTIVE_STATES, CAN_CANCEL
|
||||
from awx.main.redact import UriCleaner, REPLACE_STR
|
||||
from awx.main.consumers import emit_channel_notification
|
||||
@@ -89,9 +90,6 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
||||
|
||||
ALL_STATUS_CHOICES = OrderedDict(PROJECT_STATUS_CHOICES + INVENTORY_SOURCE_STATUS_CHOICES + JOB_TEMPLATE_STATUS_CHOICES + DEPRECATED_STATUS_CHOICES).items()
|
||||
|
||||
# NOTE: Working around a django-polymorphic issue: https://github.com/django-polymorphic/django-polymorphic/issues/229
|
||||
base_manager_name = 'base_objects'
|
||||
|
||||
class Meta:
|
||||
app_label = 'main'
|
||||
# unique_together here is intentionally commented out. Please make sure sub-classes of this model
|
||||
@@ -536,9 +534,6 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
|
||||
PASSWORD_FIELDS = ('start_args',)
|
||||
|
||||
# NOTE: Working around a django-polymorphic issue: https://github.com/django-polymorphic/django-polymorphic/issues/229
|
||||
base_manager_name = 'base_objects'
|
||||
|
||||
class Meta:
|
||||
app_label = 'main'
|
||||
|
||||
@@ -669,7 +664,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
blank=True,
|
||||
null=True,
|
||||
default=None,
|
||||
on_delete=models.SET_NULL,
|
||||
on_delete=polymorphic.SET_NULL,
|
||||
help_text=_('The Rampart/Instance group the job was run under'),
|
||||
)
|
||||
credentials = models.ManyToManyField(
|
||||
|
||||
Reference in New Issue
Block a user