mirror of
https://github.com/Hopiu/wagtail-modeltranslation.git
synced 2026-05-11 16:53:11 +00:00
Fix makemigrations bug detected by @DiogoMarques29 when Page has
dependencies
This commit is contained in:
parent
bd93e06adc
commit
271920d6eb
1 changed files with 22 additions and 10 deletions
|
|
@ -1,18 +1,30 @@
|
|||
from django.core.management.commands.makemigrations import Command as MakeMigrationsCommand
|
||||
from django.db.migrations.autodetector import MigrationAutodetector
|
||||
import copy
|
||||
|
||||
|
||||
# decorate MigrationAutodetector.changes so we can silently remove wagtailcore changes
|
||||
def changes_decorator(func):
|
||||
def wrapper(self, graph, trim_to_apps=None, convert_apps=None, migration_name=None):
|
||||
changes = func(self, graph, trim_to_apps, convert_apps, migration_name)
|
||||
if 'wagtailcore' in changes:
|
||||
del changes['wagtailcore']
|
||||
return changes
|
||||
def autodetector_decorator(func):
|
||||
def wrapper(self, from_state, to_state, questioner=None):
|
||||
# Replace to_state.app_configs.models and to_state.models' version of page with the old one
|
||||
# so no changes are detected by MigrationAutodetector
|
||||
from_state_page = from_state.concrete_apps.get_model('wagtailcore', 'page')
|
||||
new_to_state = copy.deepcopy(to_state)
|
||||
new_to_state.apps.app_configs['wagtailcore'].models['page'] = from_state_page
|
||||
new_to_state.models['wagtailcore', 'page'] = from_state.models['wagtailcore', 'page']
|
||||
|
||||
return func(self, from_state, new_to_state, questioner)
|
||||
return wrapper
|
||||
|
||||
MigrationAutodetector.changes = changes_decorator(MigrationAutodetector.changes)
|
||||
|
||||
|
||||
class Command(MakeMigrationsCommand):
|
||||
help = "Creates new migration(s) for apps except wagtailcore."
|
||||
help = "Creates new migration(s) for apps except wagtailcore's Page."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
old_autodetector_init = MigrationAutodetector.__init__
|
||||
MigrationAutodetector.__init__ = autodetector_decorator(MigrationAutodetector.__init__)
|
||||
|
||||
try:
|
||||
super(Command, self).handle(*args, **options)
|
||||
|
||||
finally:
|
||||
MigrationAutodetector.__init__ = old_autodetector_init
|
||||
|
|
|
|||
Loading…
Reference in a new issue