Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #34457 -- Restored output for makemigrations --check. #17448

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions django/core/management/commands/makemigrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def add_arguments(self, parser):
dest="check_changes",
help=(
"Exit with a non-zero status if model changes are missing migrations "
"and don't actually write them."
"and don't actually write them. Implies --dry-run."
),
)
parser.add_argument(
Expand Down Expand Up @@ -114,6 +114,8 @@ def handle(self, *app_labels, **options):
raise CommandError("The migration name must be a valid Python identifier.")
self.include_header = options["include_header"]
check_changes = options["check_changes"]
if check_changes:
self.dry_run = True
self.scriptable = options["scriptable"]
self.update = options["update"]
# If logs and prompts are diverted to stderr, remove the ERROR style.
Expand Down Expand Up @@ -251,12 +253,12 @@ def handle(self, *app_labels, **options):
else:
self.log("No changes detected")
else:
if check_changes:
sys.exit(1)
if self.update:
self.write_to_last_migration_files(changes)
else:
self.write_migration_files(changes)
if check_changes:
sys.exit(1)

def write_to_last_migration_files(self, changes):
loader = MigrationLoader(connections[DEFAULT_DB_ALIAS])
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/django-admin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ Generate migration files without Django version and timestamp header.
.. django-admin-option:: --check

Makes ``makemigrations`` exit with a non-zero status when model changes without
migrations are detected.
migrations are detected. Implies ``--dry-run``.

.. django-admin-option:: --scriptable

Expand Down
3 changes: 2 additions & 1 deletion docs/releases/4.2.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Django 4.2.8 fixes several bugs in 4.2.7.
Bugfixes
========

* ...
* Fixed a regression in Django 4.2 that caused :option:`makemigrations --check`
to stop displaying pending migrations (:ticket:`34457`).
25 changes: 20 additions & 5 deletions tests/migrations/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,20 +2392,35 @@ def test_makemigrations_with_invalid_custom_name(self):
"makemigrations", "migrations", "--name", "invalid name", "--empty"
)

def test_makemigrations_check(self):
def test_makemigrations_check_with_changes(self):
"""
makemigrations --check should exit with a non-zero status when
there are changes to an app requiring migrations.
"""
out = io.StringIO()
with self.temporary_migration_module() as tmpdir:
with self.assertRaises(SystemExit):
call_command("makemigrations", "--check", "migrations", verbosity=0)
self.assertFalse(os.path.exists(tmpdir))
with self.assertRaises(SystemExit) as cm:
call_command(
"makemigrations",
"--check",
"migrations",
stdout=out,
)
self.assertEqual(os.listdir(tmpdir), ["__init__.py"])
self.assertEqual(cm.exception.code, 1)
self.assertIn("Migrations for 'migrations':", out.getvalue())

def test_makemigrations_check_no_changes(self):
"""
makemigrations --check should exit with a zero status when there are no
changes.
"""
out = io.StringIO()
adamchainz marked this conversation as resolved.
Show resolved Hide resolved
with self.temporary_migration_module(
module="migrations.test_migrations_no_changes"
):
call_command("makemigrations", "--check", "migrations", verbosity=0)
call_command("makemigrations", "--check", "migrations", stdout=out)
self.assertEqual("No changes detected in app 'migrations'\n", out.getvalue())

def test_makemigrations_migration_path_output(self):
"""
Expand Down