Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #15548: Ignore many-to-many mappings when checking dependencies of an object being deleted #15889

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions netbox/netbox/views/generic/object_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,14 @@ def _get_dependent_objects(self, obj):

# Compile a mapping of models to instances
dependent_objects = defaultdict(list)
for model, instance in collector.instances_with_model():
for model, instances in collector.instances_with_model():
# Ignore relations to auto-created models (e.g. many-to-many mappings)
if model._meta.auto_created:
continue
# Omit the root object
if instance != obj:
dependent_objects[model].append(instance)
if instances == obj:
continue
dependent_objects[model].append(instances)

return dict(dependent_objects)

Expand Down
Loading