forked from django/django
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #35656 -- Added an autodetector attribute to the makemigrations…
… and migrate commands.
- Loading branch information
1 parent
dc626fb
commit 06bf06a
Showing
10 changed files
with
142 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.core.checks import Error, Tags, register | ||
|
||
|
||
@register(Tags.commands) | ||
def migrate_and_makemigrations_autodetector(**kwargs): | ||
from django.core.management import get_commands, load_command_class | ||
|
||
commands = get_commands() | ||
|
||
make_migrations = load_command_class(commands["makemigrations"], "makemigrations") | ||
migrate = load_command_class(commands["migrate"], "migrate") | ||
|
||
if make_migrations.autodetector is not migrate.autodetector: | ||
return [ | ||
Error( | ||
"The migrate and makemigrations commands must have the same " | ||
"autodetector.", | ||
hint=( | ||
f"makemigrations.Command.autodetector is " | ||
f"{make_migrations.autodetector.__name__}, but " | ||
f"migrate.Command.autodetector is " | ||
f"{migrate.autodetector.__name__}." | ||
), | ||
id="commands.E001", | ||
) | ||
] | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/check_framework/custom_commands_app/management/commands/makemigrations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.core.management.commands.makemigrations import ( | ||
Command as MakeMigrationsCommand, | ||
) | ||
|
||
|
||
class Command(MakeMigrationsCommand): | ||
autodetector = int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters