From 06bf06a911695c5c84f746742f764c040e237ece Mon Sep 17 00:00:00 2001 From: leondaz Date: Mon, 9 Sep 2024 19:15:40 +0300 Subject: Fixed #35656 -- Added an autodetector attribute to the makemigrations and migrate commands. --- .../management/commands/makemigrations.py | 7 ++++++ tests/check_framework/test_commands.py | 25 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/check_framework/custom_commands_app/management/commands/makemigrations.py create mode 100644 tests/check_framework/test_commands.py (limited to 'tests/check_framework') diff --git a/tests/check_framework/custom_commands_app/management/commands/makemigrations.py b/tests/check_framework/custom_commands_app/management/commands/makemigrations.py new file mode 100644 index 0000000000..a6494cba4c --- /dev/null +++ b/tests/check_framework/custom_commands_app/management/commands/makemigrations.py @@ -0,0 +1,7 @@ +from django.core.management.commands.makemigrations import ( + Command as MakeMigrationsCommand, +) + + +class Command(MakeMigrationsCommand): + autodetector = int diff --git a/tests/check_framework/test_commands.py b/tests/check_framework/test_commands.py new file mode 100644 index 0000000000..a51db77402 --- /dev/null +++ b/tests/check_framework/test_commands.py @@ -0,0 +1,25 @@ +from django.core import checks +from django.core.checks import Error +from django.test import SimpleTestCase +from django.test.utils import isolate_apps, override_settings, override_system_checks + + +@isolate_apps("check_framework.custom_commands_app", attr_name="apps") +@override_settings(INSTALLED_APPS=["check_framework.custom_commands_app"]) +@override_system_checks([checks.commands.migrate_and_makemigrations_autodetector]) +class CommandCheckTests(SimpleTestCase): + def test_migrate_and_makemigrations_autodetector_different(self): + expected_error = Error( + "The migrate and makemigrations commands must have the same " + "autodetector.", + hint=( + "makemigrations.Command.autodetector is int, but " + "migrate.Command.autodetector is MigrationAutodetector." + ), + id="commands.E001", + ) + + self.assertEqual( + checks.run_checks(app_configs=self.apps.get_app_configs()), + [expected_error], + ) -- cgit v1.3