Repository: saleor/saleor

Issue:
AttributeChoiceValue, slug field max length is much less than max length of name field
Branch: Master

### What I'm trying to achieve
Adding an attribute value that is longer than 50 characters (max allowed is 100)

### Steps to reproduce the problem

1.  Add an attribute choice value of greater than 50
2.  The slug field will throw a constraint error because it defaults to only 50

### What I expected to happen
Slug field should match length of name field

### What happened instead/how it failed
Constraint DB error gets thrown

django.db.utils.DataError: value too long for type character varying(50)



Discussion:
Other models like category have similar problem.   Since slug is based off name and really just lowercases and hyphenates spaces, we will have constraint issues.

name = models.CharField(max_length=128)
slug = models.SlugField(max_length=50)
We should go over all models and update slug fields so that the `max_length` matches with the length of a field that the slug is based on.

Resolving patch:
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.py
--- a/saleor/dashboard/collection/forms.py
+++ b/saleor/dashboard/collection/forms.py
@@ -31,5 +31,4 @@ def __init__(self, *args, **kwargs):
 
     def save(self, commit=True):
         self.instance.slug = slugify(unidecode(self.instance.name))
-        super().save(commit=commit)
-        return self.instance
+        return super().save(commit=commit)
diff --git a/saleor/product/migrations/0052_slug_field_length.py b/saleor/product/migrations/0052_slug_field_length.py
new file mode 100644
--- /dev/null
+++ b/saleor/product/migrations/0052_slug_field_length.py
@@ -0,0 +1,28 @@
+# Generated by Django 2.0.2 on 2018-02-28 11:22
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('product', '0051_auto_20180202_1106'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='attributechoicevalue',
+            name='slug',
+            field=models.SlugField(max_length=100),
+        ),
+        migrations.AlterField(
+            model_name='category',
+            name='slug',
+            field=models.SlugField(max_length=128),
+        ),
+        migrations.AlterField(
+            model_name='collection',
+            name='slug',
+            field=models.SlugField(max_length=128),
+        ),
+    ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -24,7 +24,7 @@
 
 class Category(MPTTModel):
     name = models.CharField(max_length=128)
-    slug = models.SlugField(max_length=50)
+    slug = models.SlugField(max_length=128)
     description = models.TextField(blank=True)
     parent = models.ForeignKey(
         'self', null=True, blank=True, related_name='children',
@@ -335,7 +335,7 @@ def has_values(self):
 
 class AttributeChoiceValue(models.Model):
     name = models.CharField(max_length=100)
-    slug = models.SlugField()
+    slug = models.SlugField(max_length=100)
     color = models.CharField(
         max_length=7, blank=True,
         validators=[RegexValidator('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$')])
@@ -389,7 +389,7 @@ class VariantImage(models.Model):
 
 class Collection(models.Model):
     name = models.CharField(max_length=128, unique=True)
-    slug = models.SlugField(max_length=255)
+    slug = models.SlugField(max_length=128)
     products = models.ManyToManyField(
         Product, blank=True, related_name='collections')
 


Test patch: