mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Refs #26226 -- Removed support for related manager classes without a _apply_rel_filters() method.
Per deprecation timeline.
This commit is contained in:
		| @@ -22,7 +22,6 @@ from django.db.models.functions import Trunc | ||||
| from django.db.models.query_utils import InvalidQuery, Q | ||||
| from django.db.models.sql.constants import CURSOR | ||||
| from django.utils import six, timezone | ||||
| from django.utils.deprecation import RemovedInDjango20Warning | ||||
| from django.utils.functional import cached_property, partition | ||||
| from django.utils.version import get_version | ||||
|  | ||||
| @@ -1613,19 +1612,7 @@ def prefetch_one_level(instances, prefetcher, lookup, level): | ||||
|             else: | ||||
|                 manager = getattr(obj, to_attr) | ||||
|                 if leaf and lookup.queryset is not None: | ||||
|                     try: | ||||
|                         apply_rel_filter = manager._apply_rel_filters | ||||
|                     except AttributeError: | ||||
|                         warnings.warn( | ||||
|                             "The `%s.%s` class must implement a `_apply_rel_filters()` " | ||||
|                             "method that accepts a `QuerySet` as its single " | ||||
|                             "argument and returns an appropriately filtered version " | ||||
|                             "of it." % (manager.__class__.__module__, manager.__class__.__name__), | ||||
|                             RemovedInDjango20Warning, | ||||
|                         ) | ||||
|                         qs = manager.get_queryset() | ||||
|                     else: | ||||
|                         qs = apply_rel_filter(lookup.queryset) | ||||
|                     qs = manager._apply_rel_filters(lookup.queryset) | ||||
|                 else: | ||||
|                     qs = manager.get_queryset() | ||||
|                 qs._result_cache = vals | ||||
|   | ||||
| @@ -355,3 +355,6 @@ these features. | ||||
|   ``Meta.default_related_name`` is set is removed. | ||||
|  | ||||
| * The MySQL ``__search`` lookup is removed. | ||||
|  | ||||
| * The shim for supporting custom related manager classes without a | ||||
|   ``_apply_rel_filters()`` method is removed. | ||||
|   | ||||
| @@ -1,7 +1,5 @@ | ||||
| from __future__ import unicode_literals | ||||
|  | ||||
| import warnings | ||||
|  | ||||
| from django.contrib.contenttypes.models import ContentType | ||||
| from django.core.exceptions import ObjectDoesNotExist | ||||
| from django.db import connection | ||||
| @@ -711,30 +709,6 @@ class CustomPrefetchTests(TestCase): | ||||
|             self.room2_1 | ||||
|         ) | ||||
|  | ||||
|     def test_apply_rel_filters_deprecation_shim(self): | ||||
|         # Simulate a missing `_apply_rel_filters` method. | ||||
|         del Person.houses.related_manager_cls._apply_rel_filters | ||||
|         # Also remove `get_queryset` as it rely on `_apply_rel_filters`. | ||||
|         del Person.houses.related_manager_cls.get_queryset | ||||
|         try: | ||||
|             with warnings.catch_warnings(record=True) as warns: | ||||
|                 warnings.simplefilter('always') | ||||
|                 list(Person.objects.prefetch_related( | ||||
|                     Prefetch('houses', queryset=House.objects.filter(name='House 1')) | ||||
|                 )) | ||||
|         finally: | ||||
|             # Deleting `related_manager_cls` will force the creation of a new | ||||
|             # class since it's a `cached_property`. | ||||
|             del Person.houses.related_manager_cls | ||||
|         msg = ( | ||||
|             'The `django.db.models.fields.related_descriptors.ManyRelatedManager` class ' | ||||
|             'must implement a `_apply_rel_filters()` method that accepts a `QuerySet` as ' | ||||
|             'its single argument and returns an appropriately filtered version of it.' | ||||
|         ) | ||||
|         self.assertEqual(len(warns), 2)  # Once person. | ||||
|         self.assertEqual(str(warns[0].message), msg) | ||||
|         self.assertEqual(str(warns[0].message), msg) | ||||
|  | ||||
|     def test_values_queryset(self): | ||||
|         with self.assertRaisesMessage(ValueError, 'Prefetch querysets cannot use values().'): | ||||
|             Prefetch('houses', House.objects.values('pk')) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user