#35920: Migrate command runs system checks regardless of the value of
requires_system_checks
-------------------------------------+-------------------------------------
     Reporter:  Jacob Walls          |                    Owner:  Jacob
                                     |  Walls
         Type:  Bug                  |                   Status:  assigned
    Component:  Core (Management     |                  Version:  5.1
  commands)                          |
     Severity:  Normal               |               Resolution:
     Keywords:  skip-checks          |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * needs_better_patch:  0 => 1

Comment:

 I agree that it makes sense to adjust the `migrate` and `runserver`
 commands to allow for `requires_system_checks` to be adjusted but the I
 believe the proposed solution fails to account for the fact that
 `BaseCommand.execute` (which is `.handle`'s caller)
 
[https://github.com/django/django/blob/857b1048d53ebf5fc5581c110e85c212b81ca83a/django/core/management/base.py#L452-L459
 already calls] `check` when `requires_system_checks` is not empty.

 What we want here is a single call to `self.check` with the proper
 arguments being provided (`databases` and `display_num_errors`
 respectively). In the case of `display_num_errors=Tue` it's pretty trivial
 as `runserver.Command.check` can be overridden to call `super().check()`
 but in the case of `migrate.Command` it's a bit more tricky.

 Maybe we could introduce a `get_check_kwargs(**options) -> dict: Kwargs`
 method that simplifies all that?

 {{{#!patch
 diff --git a/django/core/management/base.py
 b/django/core/management/base.py
 index 6232b42bd4..ba38ae1748 100644
 --- a/django/core/management/base.py
 +++ b/django/core/management/base.py
 @@ -450,10 +450,8 @@ def execute(self, *args, **options):
              self.stderr = OutputWrapper(options["stderr"])

          if self.requires_system_checks and not options["skip_checks"]:
 -            if self.requires_system_checks == ALL_CHECKS:
 -                self.check()
 -            else:
 -                self.check(tags=self.requires_system_checks)
 +            check_kwargs = self.get_check_kwargs(options)
 +            self.check(**check_kwargs)
          if self.requires_migrations_checks:
              self.check_migrations()
          output = self.handle(*args, **options)
 @@ -468,6 +466,11 @@ def execute(self, *args, **options):
              self.stdout.write(output)
          return output

 +    def get_check_kwargs(self, options):
 +        if self.requires_system_checks == ALL_CHECKS:
 +            return {}
 +        return {"tags": self.requires_system_checks}
 +
      def check(
          self,
          app_configs=None,
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35920#comment:4>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070193613c6506-8ef56238-b3ac-44e2-9103-ec229999a75e-000000%40eu-central-1.amazonses.com.

Reply via email to