From 2ce4545de1791d6ed2405cb0657401e179bc5357 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 23 Nov 2024 11:41:14 -0500 Subject: Fixed #35920 -- Observed requires_system_checks in migrate and runserver. Before, the full suite of system checks was run by these commands regardless if requires_system_checks had been overridden. Co-authored-by: Simon Charette --- docs/howto/custom-management-commands.txt | 15 +++++++++++++++ docs/releases/5.2.txt | 4 ++++ 2 files changed, 19 insertions(+) (limited to 'docs') diff --git a/docs/howto/custom-management-commands.txt b/docs/howto/custom-management-commands.txt index d3775905d3..de6c38c1e0 100644 --- a/docs/howto/custom-management-commands.txt +++ b/docs/howto/custom-management-commands.txt @@ -319,6 +319,21 @@ the :meth:`~BaseCommand.handle` method must be implemented. checks, and list of database aliases in the ``databases`` to run database related checks against them. +.. method:: BaseCommand.get_check_kwargs(options) + + .. versionadded:: 5.2 + + Supplies kwargs for the call to :meth:`check`, including transforming the + value of :attr:`requires_system_checks` to the ``tag`` kwarg. + + Override this method to change the values supplied to :meth:`check`. For + example, to opt into database related checks you can override + ``get_check_kwargs()`` as follows:: + + def get_check_kwargs(self, options): + kwargs = super().get_check_kwargs(options) + return {**kwargs, "databases": [options["database"]]} + .. _ref-basecommand-subclasses: ``BaseCommand`` subclasses diff --git a/docs/releases/5.2.txt b/docs/releases/5.2.txt index 907159e36d..5e692c0345 100644 --- a/docs/releases/5.2.txt +++ b/docs/releases/5.2.txt @@ -279,6 +279,10 @@ Management Commands ``Command.autodetector`` attribute for subclasses to override in order to use a custom autodetector class. +* The new :meth:`.BaseCommand.get_check_kwargs` method can be overridden in + custom commands to control the running of system checks, e.g. to opt into + database-dependent checks. + Migrations ~~~~~~~~~~ -- cgit v1.3