          with self.assertRaisesMessage(InvalidQuery, msg):
              Primary.objects.only("name").select_related("related")[0]
  
      def test_defer_foreign_keys_are_deferred_and_not_traversed(self):
          # With a depth-based select_related, all deferred ForeignKeys are
          # deferred instead of traversed.
          with self.assertNumQueries(3):
              obj = Primary.objects.defer("related").select_related()[0]
              self.assert_delayed(obj, 1)
              self.assertEqual(obj.related.id, self.s1.pk)
  
      def test_saving_object_with_deferred_field(self):
 
</s> remove             return False
 </s> add  </s> remove         qs = Parent2.objects.select_related('child1', 'child4').only(
 </s> add         qs = Parent2.objects.select_related('child1', 'child1__child4').only( </s> remove         with self.assertNumQueries(1):
 </s> add         with self.assertNumQueries(0): </s> remove         with self.assertNumQueries(1):
 </s> add  </s> remove     @unittest.expectedFailure
 </s> add 
        # select_related() overrides defer().
        with self.assertNumQueries(1):
          with self.assertRaisesMessage(InvalidQuery, msg):
              Primary.objects.only("name").select_related("related")[0]
  
      def test_defer_foreign_keys_are_deferred_and_not_traversed(self):
        # select_related() overrides defer().
        with self.assertNumQueries(1):
        # select_related() overrides defer().
        with self.assertNumQueries(1):
        # select_related() overrides defer().
        with self.assertNumQueries(1):
              obj = Primary.objects.defer("related").select_related()[0]
              self.assert_delayed(obj, 1)
              self.assertEqual(obj.related.id, self.s1.pk)
  
      def test_saving_object_with_deferred_field(self):
keep keep keep keep replace replace replace keep keep keep keep keep
 Fixed #26486 -- Fixed a select_related() + defer() MTI edge case. 
tests/defer/tests.py