Skip to content

Commit

Permalink
Fix remove_stale_contentitems when when a parent type is also removed
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Dec 6, 2016
1 parent 1c56e21 commit 7edb4a9
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ def remove_unreferenced_items(self, stale_cts):
parent_ct = ContentType.objects.get_for_id(ct_id)
unreferenced_items = (ContentItem.objects
.filter(parent_type=ct_id)
.exclude(parent_id__in=parent_ct.get_all_objects_for_this_type())
.order_by('polymorphic_ctype', 'pk'))

if parent_ct.model_class() is not None:
# Only select the items that are part of removed pages,
# unless the parent type was removed - then removing all is correct.
unreferenced_items = unreferenced_items.exclude(
parent_id__in=parent_ct.get_all_objects_for_this_type()
)

if unreferenced_items:
for item in unreferenced_items:
self.stdout.write(
Expand Down

0 comments on commit 7edb4a9

Please sign in to comment.