Commit d6bd1f26 authored by Dmitry Volodin's avatar Dmitry Volodin Committed by Andrey Vertiprahov
Browse files

Merge branch 'patch-avs-cleanup-maintenance-del-mo' into 'master'

Cleanup Maintenance.direct_object when ManagedObject delete.

See merge request !6347

(cherry picked from commit d9851618)

08bed530 Cleanup Maintenance.direct_object when ManagedObject delete.
e6642b05 Fix on_delete_handler for Array EmbeddedDocument field.
parent e6844fba
Pipeline #36571 passed with stages
in 15 minutes and 10 seconds
......@@ -172,7 +172,21 @@ def on_delete_check(check=None, clean=None, delete=None, ignore=None, clean_lazy
# Clean related
for model, model_id, field in iter_models("clean"):
for ro in iter_related(instance, model, field):
setattr(ro, field, None)
if is_document(ro) and "__" in field:
# EmbeddedDocument Array
field, e_field = field.split("__")
# ro.objects.update(**{f"pull__{field}":})
for ed in getattr(ro, field, [])
if getattr(ed, e_field, None) != instance
setattr(ro, field, None)
# Delete related
for model, model_id, field in iter_models("delete"):
......@@ -160,8 +160,6 @@ logger = logging.getLogger(__name__)
("fm.FailedEvent", "managed_object"),
("inv.Interface", "managed_object"),
("inv.SubInterface", "managed_object"),
("maintenance.Maintenance", "escalate_managed_object"),
("maintenance.Maintenance", "direct_objects__object"),
("inv.ForwardingInstance", "managed_object"),
("sa.ManagedObject", "controller"),
("sla.SLAProbe", "managed_object"),
......@@ -176,7 +174,12 @@ logger = logging.getLogger(__name__)
("sa.ObjectCapabilities", "object"),
("sa.ObjectData", "object"),
clean=[("ip.Address", "managed_object"), ("sa.Service", "managed_object")],
("ip.Address", "managed_object"),
("sa.Service", "managed_object"),
("maintenance.Maintenance", "escalate_managed_object"),
("maintenance.Maintenance", "direct_objects__object"),
class ManagedObject(NOCModel):
......@@ -944,6 +947,7 @@ class ManagedObject(NOCModel):
from noc.inv.models.discoveryid import DiscoveryID
self._reset_caches(, credential=True)
def get_index(self):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment