Skip to content

Commit 0e3c35a

Browse files
committed
Fixes #15548: Ignore many-to-many mappings when checking dependencies of an object being deleted
1 parent cbfed83 commit 0e3c35a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

netbox/netbox/views/generic/object_views.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,14 @@ def _get_dependent_objects(self, obj):
339339

340340
# Compile a mapping of models to instances
341341
dependent_objects = defaultdict(list)
342-
for model, instance in collector.instances_with_model():
342+
for model, instances in collector.instances_with_model():
343+
# Ignore relations to auto-created models (e.g. many-to-many mappings)
344+
if model._meta.auto_created:
345+
continue
343346
# Omit the root object
344-
if instance != obj:
345-
dependent_objects[model].append(instance)
347+
if instances == obj:
348+
continue
349+
dependent_objects[model].append(instances)
346350

347351
return dict(dependent_objects)
348352

0 commit comments

Comments
 (0)