Browse Source

fix[api]: Remove Email Validation on commit author (#20342)

* Changed CommitAuthor email to a CharField
Adam McKerlie 4 years ago
parent
commit
fc4e82a5cf

+ 1 - 1
migrations_lockfile.txt

@@ -10,7 +10,7 @@ auth: 0008_alter_user_username_max_length
 contenttypes: 0002_remove_content_type_name
 jira_ac: 0001_initial
 nodestore: 0001_initial
-sentry: 0119_fix_set_none
+sentry: 0120_commit_author_charfield
 sessions: 0001_initial
 sites: 0002_alter_domain_unique
 social_auth: 0001_initial

+ 2 - 2
src/sentry/api/serializers/rest_framework/commit.py

@@ -24,8 +24,8 @@ class CommitSerializer(serializers.Serializer):
     author_name = serializers.CharField(
         max_length=128, required=False, allow_null=True, allow_blank=True
     )
-    author_email = serializers.EmailField(
-        max_length=75, required=False, allow_null=True, allow_blank=True
+    author_email = serializers.CharField(
+        max_length=75, required=False, allow_null=True, allow_blank=True,
     )
     timestamp = serializers.DateTimeField(required=False, allow_null=True)
     patch_set = ListField(

+ 37 - 0
src/sentry/migrations/0120_commit_author_charfield.py

@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2020-11-02 20:25
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    # This flag is used to mark that a migration shouldn't be automatically run in
+    # production. We set this to True for operations that we think are risky and want
+    # someone from ops to run manually and monitor.
+    # General advice is that if in doubt, mark your migration as `is_dangerous`.
+    # Some things you should always mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that
+    #   they can be monitored. Since data migrations will now hold a transaction open
+    #   this is even more important.
+    # - Adding columns to highly active tables, even ones that are NULL.
+    is_dangerous = False
+
+    # This flag is used to decide whether to run this migration in a transaction or not.
+    # By default we prefer to run in a transaction, but for migrations where you want
+    # to `CREATE INDEX CONCURRENTLY` this needs to be set to False. Typically you'll
+    # want to create an index concurrently when adding one to an existing table.
+    atomic = True
+
+
+    dependencies = [
+        ('sentry', '0119_fix_set_none'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='commitauthor',
+            name='email',
+            field=models.CharField(max_length=75),
+        ),
+    ]

+ 1 - 1
src/sentry/models/commitauthor.py

@@ -21,7 +21,7 @@ class CommitAuthor(Model):
 
     organization_id = BoundedPositiveIntegerField(db_index=True)
     name = models.CharField(max_length=128, null=True)
-    email = models.EmailField(max_length=75)
+    email = models.CharField(max_length=75)
     external_id = models.CharField(max_length=164, null=True)
 
     objects = CommitAuthorManager()

+ 6 - 0
tests/sentry/api/endpoints/test_organization_release_details.py

@@ -603,3 +603,9 @@ class ReleaseSerializerTest(unittest.TestCase):
         assert serializer.is_valid()
         serializer = OrganizationReleaseSerializer(data={"ref": "a" * (MAX_VERSION_LENGTH + 1)})
         assert not serializer.is_valid()
+
+    def test_author_email_patch(self):
+        serializer = OrganizationReleaseSerializer(
+            data={"commits": [{"id": "a", "author_email": "email[test]@example.org"}]}
+        )
+        assert serializer.is_valid()