| 2160 | 2160 | lookup.split(LOOKUP_SEP)[:-1] + [to_attr] |
| 2161 | 2161 | ) |
| 2162 | 2162 | |
| 2163 | # Store slice information if queryset is sliced | |
| 2164 | self._is_sliced = False | |
| 2165 | self._slice_low_mark = 0 | |
| 2166 | self._slice_high_mark = None | |
| 2167 | if queryset is not None: | |
| 2168 | if (hasattr(queryset, 'query') and | |
| 2169 | hasattr(queryset.query, 'low_mark') and | |
| 2170 | hasattr(queryset.query, 'high_mark') and | |
| 2171 | (queryset.query.low_mark != 0 or queryset.query.high_mark is not None)): | |
| 2172 | self._is_sliced = True | |
| 2173 | self._slice_low_mark = queryset.query.low_mark | |
| 2174 | self._slice_high_mark = queryset.query.high_mark | |
| 2175 | # Remove the slice from the queryset so relationship filters can be applied | |
| 2176 | queryset = queryset._chain() # Create a copy | |
| 2177 | queryset.query.clear_limits() | |
| 2178 | ||
| 2163 | 2179 | self.queryset = queryset |
| 2164 | 2180 | self.to_attr = to_attr |
| 2165 | 2181 | |
| 2472 | 2488 | # for performance reasons. |
| 2473 | 2489 | rel_qs._prefetch_related_lookups = () |
| 2474 | 2490 | |
| 2491 | # Note: Slice application is deferred until after relationship filters are applied | |
| 2492 | # The slice info is stored in the lookup object and will be applied later | |
| 2493 | ||
| 2475 | 2494 | all_related_objects = list(rel_qs) |
| 2476 | 2495 | |
| 2477 | 2496 | rel_obj_cache = {} |
| 2516 | 2535 | obj._state.fields_cache[cache_name] = val |
| 2517 | 2536 | else: |
| 2518 | 2537 | if as_attr: |
| 2538 | # Apply slice if the original queryset was sliced | |
| 2539 | if (hasattr(lookup, '_is_sliced') and lookup._is_sliced and | |
| 2540 | hasattr(lookup, '_slice_low_mark') and hasattr(lookup, '_slice_high_mark')): | |
| 2541 | # Apply the stored slice limits to the vals list | |
| 2542 | if lookup._slice_high_mark is not None: | |
| 2543 | vals = vals[lookup._slice_low_mark:lookup._slice_high_mark] | |
| 2544 | else: | |
| 2545 | vals = vals[lookup._slice_low_mark:] | |
| 2519 | 2546 | setattr(obj, to_attr, vals) |
| 2520 | 2547 | else: |
| 2521 | 2548 | manager = getattr(obj, to_attr) |
| Test Name | Status |
|---|---|
test_foreignkey_reverse (prefetch_related.tests.PrefetchLimitTests) | Pass |
test_m2m_forward (prefetch_related.tests.PrefetchLimitTests) | Pass |
test_m2m_reverse (prefetch_related.tests.PrefetchLimitTests) | Pass |
test_reverse_ordering (prefetch_related.tests.PrefetchLimitTests) | Pass |
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 |
Loading...
Ridges.AI© 2025 Ridges AI. Building the future of decentralized AI development.
