Loading django/db/models/options.py +1 −1 Original line number Diff line number Diff line Loading @@ -535,7 +535,7 @@ class Options(object): except KeyError: # If the app registry is not ready, reverse fields are # unavailable, therefore we throw a FieldDoesNotExist exception. if not self.apps.ready: if not self.apps.models_ready: raise FieldDoesNotExist( "%s has no field named %r. The app cache isn't ready yet, " "so if this is an auto-created related field, it won't " Loading tests/admin_checks/models.py +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ class Book(models.Model): class AuthorsBooks(models.Model): author = models.ForeignKey(Author) book = models.ForeignKey(Book) featured = models.BooleanField() class State(models.Model): Loading tests/admin_checks/tests.py +17 −0 Original line number Diff line number Diff line Loading @@ -667,3 +667,20 @@ class SystemChecksTestCase(TestCase): ) ] self.assertEqual(errors, expected) def test_list_filter_works_on_through_field_even_when_apps_not_ready(self): """ Ensure list_filter can access reverse fields even when the app registry is not ready; refs #24146. """ class BookAdminWithListFilter(admin.ModelAdmin): list_filter = ['authorsbooks__featured'] # Temporarily pretending apps are not ready yet. This issue can happen # if the value of 'list_filter' refers to a 'through__field'. Book._meta.apps.ready = False try: errors = BookAdminWithListFilter.check(model=Book) self.assertEqual(errors, []) finally: Book._meta.apps.ready = True tests/model_meta/tests.py +2 −2 Original line number Diff line number Diff line Loading @@ -178,7 +178,7 @@ class GetFieldByNameTests(OptionsBaseTests): opts = Person._meta # If apps registry is not ready, get_field() searches over only # forward fields. opts.apps.ready = False opts.apps.models_ready = False try: # 'data_abstract' is a forward field, and therefore will be found self.assertTrue(opts.get_field('data_abstract')) Loading @@ -191,7 +191,7 @@ class GetFieldByNameTests(OptionsBaseTests): with self.assertRaisesMessage(FieldDoesNotExist, msg): opts.get_field('relating_baseperson') finally: opts.apps.ready = True opts.apps.models_ready = True class RelationTreeTests(TestCase): Loading Loading
django/db/models/options.py +1 −1 Original line number Diff line number Diff line Loading @@ -535,7 +535,7 @@ class Options(object): except KeyError: # If the app registry is not ready, reverse fields are # unavailable, therefore we throw a FieldDoesNotExist exception. if not self.apps.ready: if not self.apps.models_ready: raise FieldDoesNotExist( "%s has no field named %r. The app cache isn't ready yet, " "so if this is an auto-created related field, it won't " Loading
tests/admin_checks/models.py +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ class Book(models.Model): class AuthorsBooks(models.Model): author = models.ForeignKey(Author) book = models.ForeignKey(Book) featured = models.BooleanField() class State(models.Model): Loading
tests/admin_checks/tests.py +17 −0 Original line number Diff line number Diff line Loading @@ -667,3 +667,20 @@ class SystemChecksTestCase(TestCase): ) ] self.assertEqual(errors, expected) def test_list_filter_works_on_through_field_even_when_apps_not_ready(self): """ Ensure list_filter can access reverse fields even when the app registry is not ready; refs #24146. """ class BookAdminWithListFilter(admin.ModelAdmin): list_filter = ['authorsbooks__featured'] # Temporarily pretending apps are not ready yet. This issue can happen # if the value of 'list_filter' refers to a 'through__field'. Book._meta.apps.ready = False try: errors = BookAdminWithListFilter.check(model=Book) self.assertEqual(errors, []) finally: Book._meta.apps.ready = True
tests/model_meta/tests.py +2 −2 Original line number Diff line number Diff line Loading @@ -178,7 +178,7 @@ class GetFieldByNameTests(OptionsBaseTests): opts = Person._meta # If apps registry is not ready, get_field() searches over only # forward fields. opts.apps.ready = False opts.apps.models_ready = False try: # 'data_abstract' is a forward field, and therefore will be found self.assertTrue(opts.get_field('data_abstract')) Loading @@ -191,7 +191,7 @@ class GetFieldByNameTests(OptionsBaseTests): with self.assertRaisesMessage(FieldDoesNotExist, msg): opts.get_field('relating_baseperson') finally: opts.apps.ready = True opts.apps.models_ready = True class RelationTreeTests(TestCase): Loading