1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #24146 -- Fixed a missing fields regression in admin checks.

This allows using get_field() early in the app loading process.

Thanks to PirosB3 and Tim Graham.
This commit is contained in:
Collin Anderson
2015-01-14 13:29:56 -05:00
committed by Tim Graham
parent 8e8daf7c9b
commit e8171daf0c
2 changed files with 31 additions and 13 deletions

View File

@@ -169,24 +169,30 @@ class GetFieldByNameTests(OptionsBaseTests):
self.assertEqual(field_info[1:], (None, True, False))
self.assertIsInstance(field_info[0], GenericRelation)
def test_get_fields_only_searches_forward_on_apps_not_ready(self):
def test_get_fields_when_apps_not_ready(self):
opts = Person._meta
# If apps registry is not ready, get_field() searches over only
# forward fields.
opts.apps.ready = False
# Clear cached data.
opts.__dict__.pop('fields_map', None)
try:
# 'data_abstract' is a forward field, and therefore will be found
self.assertTrue(opts.get_field('data_abstract'))
msg = (
"Person has no field named 'relating_baseperson'. The app "
"Person has no field named 'some_missing_field'. The app "
"cache isn't ready yet, so if this is an auto-created related "
"field, it won't be available yet."
"field, it might not be available yet."
)
# 'data_abstract' is a reverse field, and will raise an exception
with self.assertRaisesMessage(FieldDoesNotExist, msg):
opts.get_field('relating_baseperson')
opts.get_field('some_missing_field')
# Be sure it's not cached
self.assertNotIn('fields_map', opts.__dict__)
finally:
opts.apps.ready = True
# At this point searching a related field would cache fields_map
opts.get_field('relating_baseperson')
self.assertIn('fields_map', opts.__dict__)
class RelationTreeTests(TestCase):