Commit d9851618 authored by Dmitry Volodin's avatar Dmitry Volodin
Browse files

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

Cleanup Maintenance.direct_object when ManagedObject delete.

See merge request noc/noc!6347
parents 640cc7a1 964fe0dd
......@@ -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}": instance.id})
setattr(
ro,
field,
[
ed
for ed in getattr(ro, field, [])
if getattr(ed, e_field, None) != instance
],
)
else:
setattr(ro, field, None)
ro.save()
# 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")],
clean=[
("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
DiscoveryID.clean_for_object(self)
self._reset_caches(self.id, 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