From 6731b23f256992fa3f010a16b0cc8595279ac72b Mon Sep 17 00:00:00 2001 From: Abdulwasiu Apalowo Date: Fri, 1 Nov 2024 12:27:36 +0100 Subject: [PATCH] fix: Handle cms command raising error When "python manage.py cms" is run on the CLI; it should not raise AttributeError, rather it should be caught and a nice error message should be printed Fixes #8045 --- cms/management/commands/subcommands/base.py | 2 ++ cms/tests/test_management.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/cms/management/commands/subcommands/base.py b/cms/management/commands/subcommands/base.py index 6bfefcc9025..4ee218b0f6c 100644 --- a/cms/management/commands/subcommands/base.py +++ b/cms/management/commands/subcommands/base.py @@ -60,6 +60,8 @@ def create_parser(self, prog_name, subcommand): parser = CommandParser( prog=f"{os.path.basename(prog_name)} {subcommand}", description=self.help or None, + missing_args_message=getattr(self, "missing_args_message", None), + called_from_command_line=getattr(self, "_called_from_command_line", None), **kwargs ) self.add_arguments(parser) diff --git a/cms/tests/test_management.py b/cms/tests/test_management.py index e4ebee6ed8a..eb723c620f0 100644 --- a/cms/tests/test_management.py +++ b/cms/tests/test_management.py @@ -304,6 +304,10 @@ def test_uninstall_plugins_with_plugin(self): self.assertEqual(out.getvalue(), "1 'TextPlugin' plugins uninstalled\n") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 0) + def test_for_running_only_cms_command(self): + with self.assertRaises(CommandError) as e: + management.call_command('cms') + self.assertEqual(str(e.exception), 'Error: one of the available sub commands must be provided') class PageFixtureManagementTestCase(NavextendersFixture, CMSTestCase):