

def test_select_related_with_null_relation(self):
    with translation.override('en'):
        related1 = Related.objects.language().create(normal=self.normal1, translated=rel_objects.normal1)
        related2 = Related.objects.language().create(normal=None, translated=None)
        with self.assertNumQueries(1):
            rel_objects = Related.objects.language().select_related('normal', 'translated')
            self.assertEqual(len(rel_objects), 2)
            for r in rel_objects:
                if (r.id == related1.id):
                    self.assertEqual(self.normal1.translated_field, r.normal.translated_field)
                    self.assertEqual(self.normal1.translated_field, r.translated.translated_field)
                elif (r.id == related2.id):
                    self.assertEqual(r.normal, None)
                    self.assertEqual(r.translated, None)
                else:
                    self.fail(('Invalid Related object; ID is %s' % r.id))

dataset/ETHPy150Open KristianOellegaard/django-hvad/hvad/tests/related.py SelectRelatedTests.test_select_related_with_null_relation/VarMisuse@40/54 `self`->`rel_objects`