Made Collector.collect() return immediately for disabled related collection.
@@ -210,7 +210,9 @@ class Collector:
source_attr=ptr.remote_field.related_name,
collect_related=False,
reverse_dependency=True)
- if collect_related:
+ if not collect_related:
+ return
+
if keep_parents:
parents = set(model._meta.get_parent_list())
for related in get_candidate_relations_to_delete(model._meta):
@@ -242,6 +244,7 @@ class Collector:
sub_objs = sub_objs.only(*tuple(referenced_fields))
if sub_objs:
field.remote_field.on_delete(self, field, sub_objs, self.using)
+
for field in model._meta.private_fields:
if hasattr(field, 'bulk_related_objects'):
# It's something like generic foreign key.
