#26961: Run admin checks if DEBUG is False
--------------------------------------+------------------------------------
Reporter: adamchainz | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 1.9
Severity: Normal | Resolution:
Keywords: checks | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by adamchainz):
I've re-factored the admin checks to be dynamically created, by keeping
track of all the `AdminSite` references that exist, and calling `check` on
each individually when the admin app `check` function is called. That in
itself didn't seem to cause any errors.
I've also fixed a number of checks that were failing for the model and
admin classes defined in tests, if only I'd finished #25415 and made tests
run checks again!
Another thing I had to do was make `CheckMessage` succeed in comparisons
with non-`CheckMessage` classes because some tests return plain strings
from their temporary `check` functions and then these don't compare with
real check messages that come out, and the test crashes unhelpfully.
I'm still working a couple of failures that seem broken due to the lack of
integration between checks and the app registry. Some tests fail with
checks from apps that have been unloaded through
`override_settings(INSTALLED_APPS=`. Unfortunately the app registry
doesn't reset the check registry, and it can't really because the
interface of checks allows not only to be registered during
`AppConfig.ready` but just at import time, so clearing the check registry
on app registry reload would unload those checks and then not re-register
them...
The exact failures are:
{{{
======================================================================
ERROR: test_migrate_with_system_checks
(migrations.test_commands.MigrateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py",
line 329, in run
testMethod()
File "/Users/adamj/Documents/Projects/django/django/test/utils.py", line
209, in inner
return func(*args, **kwargs)
File
"/Users/adamj/Documents/Projects/django/tests/migrations/test_commands.py",
line 65, in test_migrate_with_system_checks
call_command('migrate', skip_checks=False, no_color=True, stdout=out)
File
"/Users/adamj/Documents/Projects/django/django/core/management/__init__.py",
line 130, in call_command
return command.execute(*args, **defaults)
File
"/Users/adamj/Documents/Projects/django/django/core/management/base.py",
line 353, in execute
self.check()
File
"/Users/adamj/Documents/Projects/django/django/core/management/base.py",
line 431, in check
raise SystemCheckError(msg)
SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
<class 'admin_views.admin.ChapterXtra1Admin'>: (admin.E116) The value of
'list_filter[4]' refers to 'chap__book__promo', which does not refer to a
Field.
<class 'admin_views.admin.ChapterXtra1Admin'>: (admin.E116) The value of
'list_filter[4]' refers to 'chap__book__promo', which does not refer to a
Field.
<class 'admin_views.admin.ChapterXtra1Admin'>: (admin.E116) The value of
'list_filter[5]' refers to 'chap__book__promo__name', which does not refer
to a Field.
<class 'admin_views.admin.ChapterXtra1Admin'>: (admin.E116) The value of
'list_filter[5]' refers to 'chap__book__promo__name', which does not refer
to a Field.
======================================================================
FAIL: test_system_exit (user_commands.tests.CommandTests)
Exception raised in a command should raise CommandError with
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py",
line 329, in run
testMethod()
File
"/Users/adamj/Documents/Projects/django/tests/user_commands/tests.py",
line 60, in test_system_exit
self.assertIn("CommandError", stderr.getvalue())
File
"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py",
line 803, in assertIn
self.fail(self._formatMessage(msg, standardMsg))
File
"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py",
line 410, in fail
raise self.failureException(msg)
AssertionError: 'CommandError' not found in "\x1b[31;1mSystemCheckError:
System check identified some issues:\n\x1b[0m\nERRORS:\n\x1b[31;1m<class
'admin_views.admin.ChapterXtra1Admin'>: (admin.E116) The value of
'list_filter[4]' refers to 'chap__book__promo', which does not refer to a
Field.\x1b[0m\n\x1b[31;1m<class 'admin_views.admin.ChapterXtra1Admin'>:
(admin.E116) The value of 'list_filter[4]' refers to 'chap__book__promo',
which does not refer to a Field.\x1b[0m\n\x1b[31;1m<class
'admin_views.admin.ChapterXtra1Admin'>: (admin.E116) The value of
'list_filter[5]' refers to 'chap__book__promo__name', which does not refer
to a Field.\x1b[0m\n\x1b[31;1m<class
'admin_views.admin.ChapterXtra1Admin'>: (admin.E116) The value of
'list_filter[5]' refers to 'chap__book__promo__name', which does not refer
to a Field.\x1b[0m\n"
}}}
On its own, running the `admin_views` tests with a `call_command('check')`
inserted, the checks pass. It seems that something is affecting these
`admin_views` models before `test_migrate_with_system_checks` then re-runs
the checks and finds them failing. I can't figure it out :/
--
Ticket URL: <https://code.djangoproject.com/ticket/26961#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.6c414946d7f8c684ca94a8a93f6488d0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.