Commit 28753258 authored by Jon Dufresne's avatar Jon Dufresne Committed by Tim Graham
Browse files

Fixed #25500 -- Added --fail-level option to check command.

This option specifies the level that check command exits with a
non-zero status. Default is ``ERROR``.
parent b215a3ab
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ class CheckMessage(object):
        return "<%s: level=%r, msg=%r, hint=%r, obj=%r, id=%r>" % \
            (self.__class__.__name__, self.level, self.msg, self.hint, self.obj, self.id)

    def is_serious(self):
        return self.level >= ERROR
    def is_serious(self, level=ERROR):
        return self.level >= level

    def is_silenced(self):
        from django.conf import settings
+2 −2
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ class BaseCommand(object):
                translation.activate(saved_locale)

    def check(self, app_configs=None, tags=None, display_num_errors=False,
              include_deployment_checks=False):
              include_deployment_checks=False, fail_level=checks.ERROR):
        """
        Uses the system check framework to validate entire Django project.
        Raises CommandError for any serious message (error or critical errors).
@@ -409,7 +409,7 @@ class BaseCommand(object):
                len(all_issues) - visible_issue_count,
            )

        if any(e.is_serious() and not e.is_silenced() for e in all_issues):
        if any(e.is_serious(fail_level) and not e.is_silenced() for e in all_issues):
            msg = self.style.ERROR("SystemCheckError: %s" % header) + body + footer
            raise SystemCheckError(msg)
        else:
+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,16 @@ class Command(BaseCommand):
            help='List available tags.')
        parser.add_argument('--deploy', action='store_true', dest='deploy',
            help='Check deployment settings.')
        parser.add_argument(
            '--fail-level',
            default='ERROR',
            choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'],
            dest='fail_level',
            help=(
                'Message level that will cause the command to exit with a '
                'non-zero status. Default is ERROR.'
            ),
        )

    def handle(self, *app_labels, **options):
        include_deployment_checks = options['deploy']
@@ -49,4 +59,5 @@ class Command(BaseCommand):
            tags=tags,
            display_num_errors=True,
            include_deployment_checks=include_deployment_checks,
            fail_level=getattr(checks, options['fail_level']),
        )
+10 −0
Original line number Diff line number Diff line
@@ -147,6 +147,16 @@ Or you could run it directly on a production or staging deployment to verify
that the correct settings are in use (omitting ``--settings``). You could even
make it part of your integration test suite.

.. django-admin-option:: --fail-level

.. versionadded:: 1.10

Specifies the message level that will cause the command to exit with a non-zero
status. Default is ``ERROR``.

Available levels are: ``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO``, and
``DEBUG``.

compilemessages
---------------

+3 −1
Original line number Diff line number Diff line
@@ -150,7 +150,9 @@ Internationalization
Management Commands
^^^^^^^^^^^^^^^^^^^

* ...
* The new :djadminopt:`--fail-level` option of the :djadmin:`check` command
  allows specifying the message level that will cause the command to exit with
  a non-zero status.

Migrations
^^^^^^^^^^
Loading