From 25f57d06366a0076970c26c5ffdf5e6e0922e7e2 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Tue, 17 Jan 2017 19:19:42 +0000 Subject: [PATCH] Reduce focal_point_key max_length to 16 --- .../wagtailimages/migrations/0001_initial.py | 2 +- .../0004_make_focal_point_key_not_nullable.py | 2 +- ...016_deprecate_rendition_filter_relation.py | 28 +++++++++++++++++++ .../0017_reduce_focal_point_key_max_length.py | 24 ++++++++++++++++ wagtail/wagtailimages/models.py | 2 +- 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py diff --git a/wagtail/wagtailimages/migrations/0001_initial.py b/wagtail/wagtailimages/migrations/0001_initial.py index fa88ef387c..e8c29d7a66 100644 --- a/wagtail/wagtailimages/migrations/0001_initial.py +++ b/wagtail/wagtailimages/migrations/0001_initial.py @@ -63,7 +63,7 @@ class Migration(migrations.Migration): ('file', models.ImageField(width_field='width', upload_to='images', height_field='height')), ('width', models.IntegerField(editable=False)), ('height', models.IntegerField(editable=False)), - ('focal_point_key', models.CharField(editable=False, max_length=255, null=True)), + ('focal_point_key', models.CharField(editable=False, max_length=16, null=True)), ('filter', models.ForeignKey(on_delete=models.CASCADE, related_name='+', to='wagtailimages.Filter')), ('image', models.ForeignKey(on_delete=models.CASCADE, related_name='renditions', to='wagtailimages.Image')), ], diff --git a/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py b/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py index b62174f255..a6c8601842 100644 --- a/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py +++ b/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py @@ -44,6 +44,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='rendition', name='focal_point_key', - field=models.CharField(blank=True, default='', max_length=255, editable=False), + field=models.CharField(blank=True, default='', max_length=16, editable=False), ), ] diff --git a/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py b/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py index 619db828f6..44d51fb39e 100644 --- a/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py +++ b/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py @@ -17,6 +17,34 @@ class Migration(migrations.Migration): name='filter_spec', field=models.CharField(db_index=True, max_length=255), ), + + # New step introduced in Wagtail 1.8.1: + # + # Reduce max_length of rendition.focal_point_key to 16, from the previous value of 255 + # which existed on Wagtail <= 1.8. MySQL has a limit of 767 (on InnoDB) or 1000 (on MyISAM) + # bytes; depending on the character encoding used, this limit may be reached by the + # original index on ['image', 'filter', 'focal_point_key'] (= 1 varchar and two FKs) + # or the new index on ['image', 'filter_spec', 'focal_point_key'] (= 2 varchars and one FK). + # + # To mitigate this, we reduce focal_point_key in the following places: + # * Retrospectively in the original migration, so that configurations that previously + # failed on wagtailimages/0001_initial can now run (see #2925 / #2953); + # * Here, so that previously-working Wagtail <=1.7 installations that failed on the + # AlterUniqueTogether below when upgrading to 1.8 can now succeed; + # * In the newly-added migration wagtailimages/0017, so that existing Wagtail 1.8 installations + # that successfully applied the old 1.8 version of this migration are consistent with + # other setups. + # + # Projects with a custom image model don't have to worry about this - they'll have an existing + # migration with the max_length=255, and will get a new migration reducing it to max_length=16 + # the next time they run makemigrations. + + migrations.AlterField( + model_name='rendition', + name='focal_point_key', + field=models.CharField(blank=True, default='', max_length=16, editable=False), + ), + migrations.AlterUniqueTogether( name='rendition', unique_together=set([('image', 'filter_spec', 'focal_point_key')]), diff --git a/wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py b/wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py new file mode 100644 index 0000000000..b8350d1e89 --- /dev/null +++ b/wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailimages', '0016_deprecate_rendition_filter_relation'), + ] + + operations = [ + # The Wagtail 1.8 version of migration wagtailimages/0016 did not include the + # step to reduce focal_point_key's max_length to 16, necessary to make it work + # on some MySQL configurations. This migration serves only to ensure that + # installations upgrading from 1.8 to >=1.8.1 have this change applied; on other + # setups (where the current 0016 and 0017 are applied together), this is a no-op. + migrations.AlterField( + model_name='rendition', + name='focal_point_key', + field=models.CharField(blank=True, default='', max_length=16, editable=False), + ), + ] diff --git a/wagtail/wagtailimages/models.py b/wagtail/wagtailimages/models.py index 13136f0d26..2a8bd95f35 100644 --- a/wagtail/wagtailimages/models.py +++ b/wagtail/wagtailimages/models.py @@ -493,7 +493,7 @@ class AbstractRendition(models.Model): file = models.ImageField(upload_to=get_rendition_upload_to, width_field='width', height_field='height') width = models.IntegerField(editable=False) height = models.IntegerField(editable=False) - focal_point_key = models.CharField(max_length=255, blank=True, default='', editable=False) + focal_point_key = models.CharField(max_length=16, blank=True, default='', editable=False) @property def url(self):