Skip to content

Commit

Permalink
Merge pull request #95 from maykinmedia/fix-slug-field-length
Browse files Browse the repository at this point in the history
🐛 Fix slug field migration with appropriate max_length
  • Loading branch information
swrichards authored Aug 14, 2024
2 parents 2fcf94d + 506bd70 commit 7397741
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions zgw_consumers/migrations/0022_set_default_service_slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def generate_unique_slug(original_slug, count=0):

for row in Service.objects.all():
candidate_slug = slugify(row.label if row.label else row.api_root)
if len(candidate_slug) > 254:
candidate_slug = candidate_slug[:250]

row.slug = generate_unique_slug(candidate_slug)
row.save(update_fields=["slug"])

Expand All @@ -34,6 +37,7 @@ class Migration(migrations.Migration):
unique=False,
blank=True,
db_index=False,
max_length=255,
),
preserve_default=False,
),
Expand Down
1 change: 1 addition & 0 deletions zgw_consumers/models/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Service(RestAPIService):
help_text=_(
"A unique, human-friendly slug to identify this service. Primarily useful for cross-instance import/export."
),
max_length=255,
)
api_type = models.CharField(_("type"), max_length=20, choices=APITypes.choices)
api_root = models.CharField(_("api root url"), max_length=255, unique=True)
Expand Down

0 comments on commit 7397741

Please sign in to comment.