Prometeus

Finished
662662 queryset._add_hints(instance=self.instance)
663663 if self._db:
664664 queryset = queryset.using(self._db)
665 queryset._defer_next_filter = True
666 queryset = queryset.filter(**self.core_filters)
667 for field in self.field.foreign_related_fields:
668 val = getattr(self.instance, field.attname)
669 if val is None or (val == "" and empty_strings_as_null):
670 return queryset.none()
671 if self.field.many_to_one:
672 # Guard against field-like objects such as GenericRelation
673 # that abuse create_reverse_many_to_one_manager() with reverse
674 # one-to-many relationships instead and break known related
675 # objects assignment.
676 try:
677 target_field = self.field.target_field
678 except FieldError:
679 # The relationship has multiple target fields. Use a tuple
680 # for related object id.
681 rel_obj_id = tuple(
682 [
683 getattr(self.instance, target_field.attname)
684 for target_field in self.field.path_infos[-1].target_fields
685 ]
686 )
687 else:
688 rel_obj_id = getattr(self.instance, target_field.attname)
689 queryset._known_related_objects = {
690 self.field: {rel_obj_id: self.instance}
691 }
692 return queryset
665
666 # Check if the queryset is sliced
667 if queryset.query.is_sliced:
668 # For sliced querysets, we need to apply filters differently
669 # We'll create a new queryset with the same slice but apply filters first
670 # Get the slice parameters
671 low_mark = queryset.query.low_mark
672 high_mark = queryset.query.high_mark
673
674 # Apply filters to a fresh queryset first
675 filtered_qs = queryset.model.objects.all()
676 filtered_qs._add_hints(instance=self.instance)
677 if self._db:
678 filtered_qs = filtered_qs.using(self._db)
679 filtered_qs._defer_next_filter = True
680 filtered_qs = filtered_qs.filter(**self.core_filters)
681
682 # Apply the slice to the filtered queryset
683 filtered_qs.query.set_limits(low_mark, high_mark)
684
685 # Check for null values in foreign key fields
686 for field in self.field.foreign_related_fields:
687 val = getattr(self.instance, field.attname)
688 if val is None or (val == "" and empty_strings_as_null):
689 return filtered_qs.none()
690
691 # Set known related objects
692 if self.field.many_to_one:
693 # Guard against field-like objects such as GenericRelation
694 # that abuse create_reverse_many_to_one_manager() with reverse
695 # one-to-many relationships instead and break known related
696 # objects assignment.
697 try:
698 target_field = self.field.target_field
699 except FieldError:
700 # The relationship has multiple target fields. Use a tuple
701 # for related object id.
702 rel_obj_id = tuple(
703 [
704 getattr(self.instance, target_field.attname)
705 for target_field in self.field.path_infos[-1].target_fields
706 ]
707 )
708 else:
709 rel_obj_id = getattr(self.instance, target_field.attname)
710 filtered_qs._known_related_objects = {
711 self.field: {rel_obj_id: self.instance}
712 }
713 return filtered_qs
714 else:
715 # Original logic for non-sliced querysets
716 queryset._defer_next_filter = True
717 queryset = queryset.filter(**self.core_filters)
718 for field in self.field.foreign_related_fields:
719 val = getattr(self.instance, field.attname)
720 if val is None or (val == "" and empty_strings_as_null):
721 return queryset.none()
722 if self.field.many_to_one:
723 # Guard against field-like objects such as GenericRelation
724 # that abuse create_reverse_many_to_one_manager() with reverse
725 # one-to-many relationships instead and break known related
726 # objects assignment.
727 try:
728 target_field = self.field.target_field
729 except FieldError:
730 # The relationship has multiple target fields. Use a tuple
731 # for related object id.
732 rel_obj_id = tuple(
733 [
734 getattr(self.instance, target_field.attname)
735 for target_field in self.field.path_infos[-1].target_fields
736 ]
737 )
738 else:
739 rel_obj_id = getattr(self.instance, target_field.attname)
740 queryset._known_related_objects = {
741 self.field: {rel_obj_id: self.instance}
742 }
743 return queryset
693744
694745 def _remove_prefetched_objects(self):
695746 try:
719770 instance_attr = self.field.get_foreign_related_value
720771 instances_dict = {instance_attr(inst): inst for inst in instances}
721772 query = {"%s__in" % self.field.name: instances}
722 queryset = queryset.filter(**query)
773
774 # Check if the queryset is sliced
775 if queryset.query.is_sliced:
776 # For sliced querysets, we need to apply filters differently
777 # We'll create a new queryset with the same slice but apply filters first
778 # Get the slice parameters
779 low_mark = queryset.query.low_mark
780 high_mark = queryset.query.high_mark
781
782 # Apply filters to a fresh queryset first
783 filtered_qs = queryset.model.objects.all()
784 filtered_qs._add_hints(instance=instances[0])
785 filtered_qs = filtered_qs.using(queryset._db or self._db)
786 filtered_qs = filtered_qs.filter(**query)
787
788 # Apply the slice to the filtered queryset
789 filtered_qs.query.set_limits(low_mark, high_mark)
790
791 queryset = filtered_qs
792 else:
793 # Original logic for non-sliced querysets
794 queryset = queryset.filter(**query)
723795
724796 # Since we just bypassed this class' get_queryset(), we must manage
725797 # the reverse relation manually.
10281100 queryset._add_hints(instance=self.instance)
10291101 if self._db:
10301102 queryset = queryset.using(self._db)
1031 queryset._defer_next_filter = True
1032 return queryset._next_is_sticky().filter(**self.core_filters)
1103
1104 # Check if the queryset is sliced
1105 if queryset.query.is_sliced:
1106 # For sliced querysets, we need to apply filters differently
1107 # We'll create a new queryset with the same slice but apply filters first
1108 # Get the slice parameters
1109 low_mark = queryset.query.low_mark
1110 high_mark = queryset.query.high_mark
1111
1112 # Apply filters to a fresh queryset first
1113 filtered_qs = queryset.model.objects.all()
1114 filtered_qs._add_hints(instance=self.instance)
1115 if self._db:
1116 filtered_qs = filtered_qs.using(self._db)
1117 filtered_qs._defer_next_filter = True
1118 filtered_qs = filtered_qs.filter(**self.core_filters)
1119
1120 # Apply the slice to the filtered queryset
1121 filtered_qs.query.set_limits(low_mark, high_mark)
1122
1123 return filtered_qs._next_is_sticky()
1124 else:
1125 # Original logic for non-sliced querysets
1126 queryset._defer_next_filter = True
1127 return queryset._next_is_sticky().filter(**self.core_filters)
10331128
10341129 def _remove_prefetched_objects(self):
10351130 try:
10521147 queryset = queryset.using(queryset._db or self._db)
10531148
10541149 query = {"%s__in" % self.query_field_name: instances}
1055 queryset = queryset._next_is_sticky().filter(**query)
1150
1151 # Check if the queryset is sliced
1152 if queryset.query.is_sliced:
1153 # For sliced querysets, we need to apply filters differently
1154 # We'll create a new queryset with the same slice but apply filters first
1155 # Get the slice parameters
1156 low_mark = queryset.query.low_mark
1157 high_mark = queryset.query.high_mark
1158
1159 # Apply filters to a fresh queryset first
1160 filtered_qs = queryset.model.objects.all()
1161 filtered_qs._add_hints(instance=instances[0])
1162 filtered_qs = filtered_qs.using(queryset._db or self._db)
1163 filtered_qs = filtered_qs._next_is_sticky().filter(**query)
1164
1165 # Apply the slice to the filtered queryset
1166 filtered_qs.query.set_limits(low_mark, high_mark)
1167
1168 queryset = filtered_qs
1169 else:
1170 # Original logic for non-sliced querysets
1171 queryset = queryset._next_is_sticky().filter(**query)
10561172
10571173 # M2M: need to annotate the query in order to get the primary model
10581174 # that the secondary model was actually related to. We know that
Test NameStatus
test_foreignkey_reverse (prefetch_related.tests.PrefetchLimitTests)
Fail
test_m2m_forward (prefetch_related.tests.PrefetchLimitTests)
Fail
test_m2m_reverse (prefetch_related.tests.PrefetchLimitTests)
Fail
test_reverse_ordering (prefetch_related.tests.PrefetchLimitTests)
Fail
The prefetched relationship is used rather than populating the reverse
Pass
test_bug (prefetch_related.tests.Ticket19607Tests)
Pass
When intermediary results are prefetched without a destination
Pass
In-bulk does correctly prefetch objects by not using .iterator()
Pass
test_prefetch_nullable (prefetch_related.tests.NullableTest)
Pass
test_traverse_nullable (prefetch_related.tests.NullableTest)
Pass
test_bug (prefetch_related.tests.Ticket21410Tests)
Pass
test_bug (prefetch_related.tests.Ticket21760Tests)
Pass
test_m2m_then_m2m (prefetch_related.tests.DefaultManagerTests)
Pass
test_order (prefetch_related.tests.LookupOrderingTest)
Pass
test_foreignkey (prefetch_related.tests.ForeignKeyToFieldTest)
Pass
test_m2m (prefetch_related.tests.ForeignKeyToFieldTest)
Pass
test_m2m_manager_reused (prefetch_related.tests.ForeignKeyToFieldTest)
Pass
test_basic (prefetch_related.tests.RawQuerySetTests)
Pass
test_clear (prefetch_related.tests.RawQuerySetTests)
Pass
test_prefetch_before_raw (prefetch_related.tests.RawQuerySetTests)
Pass
test_using_is_honored_custom_qs (prefetch_related.tests.MultiDbTests)
Pass
test_using_is_honored_fkey (prefetch_related.tests.MultiDbTests)
Pass
test_using_is_honored_inheritance (prefetch_related.tests.MultiDbTests)
Pass
test_using_is_honored_m2m (prefetch_related.tests.MultiDbTests)
Pass
test_child_link_prefetch (prefetch_related.tests.MultiTableInheritanceTest)
Pass
test_foreignkey (prefetch_related.tests.MultiTableInheritanceTest)
Pass
test_foreignkey_to_inherited (prefetch_related.tests.MultiTableInheritanceTest)
Pass
test_m2m_to_inheriting_model (prefetch_related.tests.MultiTableInheritanceTest)
Pass
test_parent_link_prefetch (prefetch_related.tests.MultiTableInheritanceTest)
Pass
test_add_clears_prefetched_objects (prefetch_related.tests.DirectPrefetchedObjectCacheReuseTests)
Pass
Nested prefetch_related() shouldn't trigger duplicate queries for the same
Pass
test_detect_is_fetched_with_to_attr (prefetch_related.tests.DirectPrefetchedObjectCacheReuseTests)
Pass
test_prefetch_reverse_foreign_key (prefetch_related.tests.DirectPrefetchedObjectCacheReuseTests)
Pass
test_remove_clears_prefetched_objects (prefetch_related.tests.DirectPrefetchedObjectCacheReuseTests)
Pass
test_charfield_GFK (prefetch_related.tests.GenericRelationTests)
Pass
test_custom_queryset (prefetch_related.tests.GenericRelationTests)
Pass
test_deleted_GFK (prefetch_related.tests.GenericRelationTests)
Pass
test_generic_relation (prefetch_related.tests.GenericRelationTests)
Pass
test_nullable_GFK (prefetch_related.tests.GenericRelationTests)
Pass
test_prefetch_GFK (prefetch_related.tests.GenericRelationTests)
Pass
test_prefetch_GFK_fk_pk (prefetch_related.tests.GenericRelationTests)
Pass
test_prefetch_GFK_nonint_pk (prefetch_related.tests.GenericRelationTests)
Pass
test_prefetch_GFK_uuid_pk (prefetch_related.tests.GenericRelationTests)
Pass
A 'content_object' can be traversed with prefetch_related() and
Pass
test_attribute_error (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_bool (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_clear (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_count (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_exists (prefetch_related.tests.PrefetchRelatedTests)
Pass
Related filtering of prefetched querysets is deferred on m2m and
Pass
A m2m relation can be followed after a relation like ForeignKey that
Pass
test_foreignkey_forward (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_foreignkey_reverse (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_forward_m2m_to_attr_conflict (prefetch_related.tests.PrefetchRelatedTests)
Pass
Objects retrieved with .get() get the prefetch behavior.
Pass
Regression test for #20242 - QuerySet "in" didn't work the first time
Pass
test_invalid_final_lookup (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_len (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_m2m_forward (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_m2m_prefetching_iterator_with_chunks (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_m2m_prefetching_iterator_without_chunks (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_m2m_prefetching_iterator_without_chunks_warning (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_m2m_reverse (prefetch_related.tests.PrefetchRelatedTests)
Pass
A m2m can be followed through another m2m.
Pass
test_m2m_then_m2m_object_ids (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_m2m_then_reverse_fk_object_ids (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_m2m_then_reverse_one_to_one_object_ids (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_named_values_list (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_onetoone_reverse_no_match (prefetch_related.tests.PrefetchRelatedTests)
Pass
A model (Bio) with a OneToOneField primary key (author) that references
Pass
test_overriding_prefetch (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_prefetch_eq (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_reverse_m2m_to_attr_conflict (prefetch_related.tests.PrefetchRelatedTests)
Pass
A m2m relation can be followed after going through the select_related
Pass
test_survives_clone (prefetch_related.tests.PrefetchRelatedTests)
Pass
test_ambiguous (prefetch_related.tests.CustomPrefetchTests)
Pass
test_custom_qs (prefetch_related.tests.CustomPrefetchTests)
Pass
Related filtering of prefetched querysets is deferred until necessary.
Pass
test_generic_rel (prefetch_related.tests.CustomPrefetchTests)
Pass
test_m2m (prefetch_related.tests.CustomPrefetchTests)
Pass
test_m2m_through_fk (prefetch_related.tests.CustomPrefetchTests)
Pass
test_m2m_through_gfk (prefetch_related.tests.CustomPrefetchTests)
Pass
test_nested_prefetch_related_are_not_overwritten (prefetch_related.tests.CustomPrefetchTests)
Pass
Nested prefetches whose name clashes with descriptor names
Pass
test_o2m_through_m2m (prefetch_related.tests.CustomPrefetchTests)
Pass
test_raw_queryset (prefetch_related.tests.CustomPrefetchTests)
Pass
test_reverse_m2m (prefetch_related.tests.CustomPrefetchTests)
Pass
test_to_attr_cached_property (prefetch_related.tests.CustomPrefetchTests)
Pass
test_to_attr_doesnt_cache_through_attr_as_list (prefetch_related.tests.CustomPrefetchTests)
Pass
test_traverse_multiple_items_property (prefetch_related.tests.CustomPrefetchTests)
Pass
test_traverse_qs (prefetch_related.tests.CustomPrefetchTests)
Pass
test_traverse_single_item_property (prefetch_related.tests.CustomPrefetchTests)
Pass
test_values_queryset (prefetch_related.tests.CustomPrefetchTests)
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.