mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Refs #28586 -- Copied fetch modes to related objects.
This change ensures that behavior and performance remain consistent when traversing relationships.
This commit is contained in:
		
				
					committed by
					
						 Jacob Walls
						Jacob Walls
					
				
			
			
				
	
			
			
			
						parent
						
							821619aa87
						
					
				
				
					commit
					6dc9b04018
				
			| @@ -5,6 +5,7 @@ from operator import attrgetter | ||||
|  | ||||
| from django.core.exceptions import FieldError, ValidationError | ||||
| from django.db import connection, models | ||||
| from django.db.models import FETCH_PEERS | ||||
| from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature | ||||
| from django.test.utils import CaptureQueriesContext, isolate_apps | ||||
| from django.utils import translation | ||||
| @@ -603,6 +604,42 @@ class MultiColumnFKTests(TestCase): | ||||
|             [m4], | ||||
|         ) | ||||
|  | ||||
|     def test_fetch_mode_copied_forward_fetching_one(self): | ||||
|         person = Person.objects.fetch_mode(FETCH_PEERS).get(pk=self.bob.pk) | ||||
|         self.assertEqual(person._state.fetch_mode, FETCH_PEERS) | ||||
|         self.assertEqual( | ||||
|             person.person_country._state.fetch_mode, | ||||
|             FETCH_PEERS, | ||||
|         ) | ||||
|  | ||||
|     def test_fetch_mode_copied_forward_fetching_many(self): | ||||
|         people = list(Person.objects.fetch_mode(FETCH_PEERS)) | ||||
|         person = people[0] | ||||
|         self.assertEqual(person._state.fetch_mode, FETCH_PEERS) | ||||
|         self.assertEqual( | ||||
|             person.person_country._state.fetch_mode, | ||||
|             FETCH_PEERS, | ||||
|         ) | ||||
|  | ||||
|     def test_fetch_mode_copied_reverse_fetching_one(self): | ||||
|         country = Country.objects.fetch_mode(FETCH_PEERS).get(pk=self.usa.pk) | ||||
|         self.assertEqual(country._state.fetch_mode, FETCH_PEERS) | ||||
|         person = country.person_set.get(pk=self.bob.pk) | ||||
|         self.assertEqual( | ||||
|             person._state.fetch_mode, | ||||
|             FETCH_PEERS, | ||||
|         ) | ||||
|  | ||||
|     def test_fetch_mode_copied_reverse_fetching_many(self): | ||||
|         countries = list(Country.objects.fetch_mode(FETCH_PEERS)) | ||||
|         country = countries[0] | ||||
|         self.assertEqual(country._state.fetch_mode, FETCH_PEERS) | ||||
|         person = country.person_set.earliest("pk") | ||||
|         self.assertEqual( | ||||
|             person._state.fetch_mode, | ||||
|             FETCH_PEERS, | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class TestModelCheckTests(SimpleTestCase): | ||||
|     @isolate_apps("foreign_object") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user