Repository: getsentry/sentry
Pull request: fix: "Create project" on UI truncates long project names
Pass `max_length=50` to `slugify_instance()` when called for `Project` model: max length now matches `django.db.models.SlugField`'s `max_length`.

~Partially solves #16616: user still can submit *project name* with max length 64 via project setup wizard (serializer max length; model's max length is even bigger - 200), but later in project settings they can only modify *project slug* which has max length of 50. Not sure if project name is used anywhere and why it's a required field and why frontend sends slug as a name.. but at least there is now a matching max length for slugified value and slug field in the backend.~

**EDIT:** Fixes #16616. A user can submit *project name* with max length 50 (which is already slugified by frontend) via project setup wizard and later in project settings they can modify *project slug* with the same max length of 50. Error is shown if max length is greater than 50, no unexpected truncation to 30 chars.

Problem statement:
"Create project" in the sentry GUI truncates long project names
If I create a new project with the name "abcdefghi-abcdefghi-abcdefghi-abcdefghi-abcdefghi-" then its name becomes truncated to 30 characters ("abcdefghi-abcdefghi-abcdefghi-"). I am allowed to enter a long project name in the project creation wizard and I am not informed anywhere that the truncation will occur.

Once the project has been created I can successfully rename it to something longer than 30 characters via the project's Project Settings page.

Hints from issue discussion:
Can someone check https://github.com/getsentry/sentry/pull/21586 ?

Commit message: Sync slug and name fields max lengths

This is done to avoid confusion: previously client could
send a longer project *name* (up to 64) and part of it could get
truncated without any warnings up to 50 and then be slugified and
saved as *slug* field.

Now there is no such unexpected truncation behavior, because
user can't provide a name longer than 50.

Patch to review:
diff --git a/src/sentry/api/endpoints/team_projects.py b/src/sentry/api/endpoints/team_projects.py
index 150ce394c76243..5550514c2ca7df 100644
--- a/src/sentry/api/endpoints/team_projects.py
+++ b/src/sentry/api/endpoints/team_projects.py
@@ -15,7 +15,7 @@
 
 
 class ProjectSerializer(serializers.Serializer):
-    name = serializers.CharField(max_length=64, required=True)
+    name = serializers.CharField(max_length=50, required=True)
     slug = serializers.RegexField(r"^[a-z0-9_\-]+$", max_length=50, required=False, allow_null=True)
     platform = serializers.CharField(required=False, allow_blank=True, allow_null=True)
     default_rules = serializers.BooleanField(required=False, initial=True)
diff --git a/src/sentry/db/models/utils.py b/src/sentry/db/models/utils.py
index 6193459fb5cec4..602394c82eeae3 100644
--- a/src/sentry/db/models/utils.py
+++ b/src/sentry/db/models/utils.py
@@ -54,7 +54,7 @@ def _resolve(instance, node):
 resolve_expression_node = resolve_combined_expression
 
 
-def slugify_instance(inst, label, reserved=(), max_length=30, field_name="slug", *args, **kwargs):
+def slugify_instance(inst, label, reserved=(), max_length=50, field_name="slug", *args, **kwargs):
     base_value = slugify(label)[:max_length]
 
     if base_value is not None:


Code review comments:
diff_hunk: @@ -54,7 +54,7 @@ def _resolve(instance, node):
 resolve_expression_node = resolve_combined_expression
 
 
-def slugify_instance(inst, label, reserved=(), max_length=30, field_name="slug", *args, **kwargs):
+def slugify_instance(inst, label, reserved=(), max_length=50, field_name="slug", *args, **kwargs):
path: src/sentry/db/models/utils.py
text: @user1:
Any reason to not change the call sites instead of the default? Changing the call sites would prevent any unintended side effects.

@author:
@user1 I can add it, but IMHO it's better to carefully check just once instead of always keeping in mind to provide value for `max_length` for any function usage in future code (to not introduce same unexpected truncation). 
Actually even better approach could be to set default to `None` and assign `max_length` dynamically from the field if no value given.