19680 fix Collector and test

This commit is contained in:
Arthur 2025-06-09 14:39:51 -07:00
parent cf4f0982c5
commit 21f30070e6
2 changed files with 8 additions and 18 deletions

View File

@ -335,14 +335,16 @@ class ChangeLogViewTest(ModelViewTestCase):
response = self.client.post(**request)
self.assertHttpStatus(response, 302)
# Get the last 3 ObjectChange records ordered by time
changes = ObjectChange.objects.order_by('-time')[:3]
# Get the ObjectChange records for delete actions ordered by time
changes = ObjectChange.objects.filter(
action=ObjectChangeActionChoices.ACTION_DELETE
).order_by('time')[:3]
# Verify the order of deletion
self.assertEqual(len(changes), 3)
self.assertEqual(changes[0].changed_object_type, ContentType.objects.get_for_model(Device))
self.assertEqual(changes[0].changed_object_type, ContentType.objects.get_for_model(CableTermination))
self.assertEqual(changes[1].changed_object_type, ContentType.objects.get_for_model(Interface))
self.assertEqual(changes[2].changed_object_type, ContentType.objects.get_for_model(CableTermination))
self.assertEqual(changes[2].changed_object_type, ContentType.objects.get_for_model(Device))
class ChangeLogAPITest(APITestCase):

View File

@ -69,20 +69,8 @@ class CustomCollector(Collector):
continue
processed_relations.add(relation_key)
# Get the related objects
related_objs = getattr(instance, field.name).all()
if related_objs:
# Add them to the dependency graph
self.collect(
related_objs,
source=instance,
nullable=True,
collect_related=True,
source_attr=field.name,
reverse_dependency=True,
keep_parents=keep_parents,
fail_on_restricted=False,
)
# Add the model that the generic relation points to as a dependency
self.add_dependency(field.related_model, instance, reverse_dependency=True)
class DeleteMixin: