Commit 4d8a1eb3 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

release-22.1:Backport!6347

parent e6844fba
...@@ -172,7 +172,21 @@ def on_delete_check(check=None, clean=None, delete=None, ignore=None, clean_lazy ...@@ -172,7 +172,21 @@ def on_delete_check(check=None, clean=None, delete=None, ignore=None, clean_lazy
# Clean related # Clean related
for model, model_id, field in iter_models("clean"): for model, model_id, field in iter_models("clean"):
for ro in iter_related(instance, model, field): 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() ro.save()
# Delete related # Delete related
for model, model_id, field in iter_models("delete"): for model, model_id, field in iter_models("delete"):
......
...@@ -160,8 +160,6 @@ logger = logging.getLogger(__name__) ...@@ -160,8 +160,6 @@ logger = logging.getLogger(__name__)
("fm.FailedEvent", "managed_object"), ("fm.FailedEvent", "managed_object"),
("inv.Interface", "managed_object"), ("inv.Interface", "managed_object"),
("inv.SubInterface", "managed_object"), ("inv.SubInterface", "managed_object"),
("maintenance.Maintenance", "escalate_managed_object"),
("maintenance.Maintenance", "direct_objects__object"),
("inv.ForwardingInstance", "managed_object"), ("inv.ForwardingInstance", "managed_object"),
("sa.ManagedObject", "controller"), ("sa.ManagedObject", "controller"),
("sla.SLAProbe", "managed_object"), ("sla.SLAProbe", "managed_object"),
...@@ -176,7 +174,12 @@ logger = logging.getLogger(__name__) ...@@ -176,7 +174,12 @@ logger = logging.getLogger(__name__)
("sa.ObjectCapabilities", "object"), ("sa.ObjectCapabilities", "object"),
("sa.ObjectData", "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): class ManagedObject(NOCModel):
""" """
...@@ -944,6 +947,7 @@ class ManagedObject(NOCModel): ...@@ -944,6 +947,7 @@ class ManagedObject(NOCModel):
from noc.inv.models.discoveryid import DiscoveryID from noc.inv.models.discoveryid import DiscoveryID
DiscoveryID.clean_for_object(self) DiscoveryID.clean_for_object(self)
self._reset_caches(self.id, credential=True)
def get_index(self): 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