Skip to content

Commit

Permalink
Addressed a crash on Django 4.1+ for makemigrations --merge.
Browse files Browse the repository at this point in the history
Thanks @AvivAvitan for the report.
  • Loading branch information
charettes committed Jan 23, 2023
1 parent c5185f6 commit 222a461
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
12 changes: 7 additions & 5 deletions syzygy/management/commands/makemigrations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from functools import partial

from django.core.management.commands import makemigrations # type: ignore

from syzygy.autodetector import MigrationAutodetector
Expand All @@ -23,9 +21,13 @@ def handle(self, *args, disable_syzygy, **options):
# Monkey-patch makemigrations.MigrationAutodetector since the command
# doesn't allow it to be overridden in any other way.
MigrationAutodetector_ = makemigrations.MigrationAutodetector
makemigrations.MigrationAutodetector = partial(
MigrationAutodetector, style=self.style
)
style = self.style

class StyledMigrationAutodetector(MigrationAutodetector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, style=style)

makemigrations.MigrationAutodetector = StyledMigrationAutodetector
try:
super().handle(*args, **options)
finally:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,20 @@ def test_null_field_removal(self):
self.assertIn("- Set database DEFAULT of field bar on foo", output)
self.assertIn("null_field_removal/0003_remove_foo_bar.py", output)
self.assertIn("- Remove field bar from foo", output)

@override_settings(
MIGRATION_MODULES={"tests": "tests.test_migrations.merge_conflict"}
)
def test_merge_conflict(self):
stdout = StringIO()
call_command(
"makemigrations",
"tests",
merge=True,
interactive=False,
no_color=True,
dry_run=True,
stdout=stdout,
)
self.assertIn("0002_first", stdout.getvalue())
self.assertIn("0002_second", stdout.getvalue())
5 changes: 5 additions & 0 deletions tests/test_migrations/merge_conflict/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.db import migrations


class Migration(migrations.Migration):
pass
5 changes: 5 additions & 0 deletions tests/test_migrations/merge_conflict/0002_first.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [("tests", "0001_initial")]
5 changes: 5 additions & 0 deletions tests/test_migrations/merge_conflict/0002_second.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [("tests", "0001_initial")]
Empty file.

0 comments on commit 222a461

Please sign in to comment.