prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Validate profile fields on form
  Related code
  
  https://github.com/rtfd/readthedocs.org/blob/164800694a25d769234c6e7019c483f347fe9226/readthedocs/core/forms.py#L20-L46
  
  This will raise an exception if the length is greater than the model
  
  Sentry issue https://sentry.io/read-the-docs/readthedocs-org/issues/666774301/
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `readthedocs/core/forms.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 """Forms for core app."""
  3 
  4 from __future__ import (
  5     absolute_import, division, print_function, unicode_literals)
  6 
  7 import logging
  8 from builtins import object
  9 
  10 from django import forms
  11 from django.contrib.auth.models import User
  12 from django.forms.fields import CharField
  13 from django.utils.translation import ugettext_lazy as _
  14 
  15 from .models import UserProfile
  16 
  17 log = logging.getLogger(__name__)
  18 
  19 
  20 class UserProfileForm(forms.ModelForm):
  21     first_name = CharField(label=_('First name'), required=False)
  22     last_name = CharField(label=_('Last name'), required=False)
  23 
  24     class Meta(object):
  25         model = UserProfile
  26         # Don't allow users edit someone else's user page
  27         fields = ['first_name', 'last_name', 'homepage']
  28 
  29     def __init__(self, *args, **kwargs):
  30         super(UserProfileForm, self).__init__(*args, **kwargs)
  31         try:
  32             self.fields['first_name'].initial = self.instance.user.first_name
  33             self.fields['last_name'].initial = self.instance.user.last_name
  34         except AttributeError:
  35             pass
  36 
  37     def save(self, commit=True):
  38         first_name = self.cleaned_data.pop('first_name', None)
  39         last_name = self.cleaned_data.pop('last_name', None)
  40         profile = super(UserProfileForm, self).save(commit=commit)
  41         if commit:
  42             user = profile.user
  43             user.first_name = first_name
  44             user.last_name = last_name
  45             user.save()
  46         return profile
  47 
  48 
  49 class UserDeleteForm(forms.ModelForm):
  50     username = CharField(
  51         label=_('Username'),
  52         help_text=_('Please type your username to confirm.'),
  53     )
  54 
  55     class Meta(object):
  56         model = User
  57         fields = ['username']
  58 
  59     def clean_username(self):
  60         data = self.cleaned_data['username']
  61 
  62         if self.instance.username != data:
  63             raise forms.ValidationError(_('Username does not match!'))
  64 
  65         return data
  66 
  67 
  68 class UserAdvertisingForm(forms.ModelForm):
  69     class Meta(object):
  70         model = UserProfile
  71         fields = ['allow_ads']
  72 
  73 
  74 class FacetField(forms.MultipleChoiceField):
  75 
  76     """
  77     For filtering searches on a facet.
  78 
  79     Has validation for the format of facet values.
  80     """
  81 
  82     def valid_value(self, value):
  83         """
  84         Although this is a choice field, no choices need to be supplied.
  85 
  86         Instead, we just validate that the value is in the correct format for
  87         facet filtering (facet_name:value)
  88         """
  89         if ':' not in value:
  90             return False
  91         return True
  92
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/readthedocs/core/forms.py b/readthedocs/core/forms.py
  --- a/readthedocs/core/forms.py
  +++ b/readthedocs/core/forms.py
  @@ -18,8 +18,8 @@
   
   
   class UserProfileForm(forms.ModelForm):
  -    first_name = CharField(label=_('First name'), required=False)
  -    last_name = CharField(label=_('Last name'), required=False)
  +    first_name = CharField(label=_('First name'), required=False, max_length=30)
  +    last_name = CharField(label=_('Last name'), required=False, max_length=30)
   
       class Meta(object):
           model = UserProfile
  
verification_info: {"golden_diff": "diff --git a/readthedocs/core/forms.py b/readthedocs/core/forms.py\n--- a/readthedocs/core/forms.py\n+++ b/readthedocs/core/forms.py\n@@ -18,8 +18,8 @@\n \n \n class UserProfileForm(forms.ModelForm):\n-    first_name = CharField(label=_('First name'), required=False)\n-    last_name = CharField(label=_('Last name'), required=False)\n+    first_name = CharField(label=_('First name'), required=False, max_length=30)\n+    last_name = CharField(label=_('Last name'), required=False, max_length=30)\n \n     class Meta(object):\n         model = UserProfile\n", "issue": "Validate profile fields on form\nRelated code\r\n\r\nhttps://github.com/rtfd/readthedocs.org/blob/164800694a25d769234c6e7019c483f347fe9226/readthedocs/core/forms.py#L20-L46\r\n\r\nThis will raise an exception if the length is greater than the model\r\n\r\nSentry issue https://sentry.io/read-the-docs/readthedocs-org/issues/666774301/\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Forms for core app.\"\"\"\n\nfrom __future__ import (\n    absolute_import, division, print_function, unicode_literals)\n\nimport logging\nfrom builtins import object\n\nfrom django import forms\nfrom django.contrib.auth.models import User\nfrom django.forms.fields import CharField\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom .models import UserProfile\n\nlog = logging.getLogger(__name__)\n\n\nclass UserProfileForm(forms.ModelForm):\n    first_name = CharField(label=_('First name'), required=False)\n    last_name = CharField(label=_('Last name'), required=False)\n\n    class Meta(object):\n        model = UserProfile\n        # Don't allow users edit someone else's user page\n        fields = ['first_name', 'last_name', 'homepage']\n\n    def __init__(self, *args, **kwargs):\n        super(UserProfileForm, self).__init__(*args, **kwargs)\n        try:\n            self.fields['first_name'].initial = self.instance.user.first_name\n            self.fields['last_name'].initial = self.instance.user.last_name\n        except AttributeError:\n            pass\n\n    def save(self, commit=True):\n        first_name = self.cleaned_data.pop('first_name', None)\n        last_name = self.cleaned_data.pop('last_name', None)\n        profile = super(UserProfileForm, self).save(commit=commit)\n        if commit:\n            user = profile.user\n            user.first_name = first_name\n            user.last_name = last_name\n            user.save()\n        return profile\n\n\nclass UserDeleteForm(forms.ModelForm):\n    username = CharField(\n        label=_('Username'),\n        help_text=_('Please type your username to confirm.'),\n    )\n\n    class Meta(object):\n        model = User\n        fields = ['username']\n\n    def clean_username(self):\n        data = self.cleaned_data['username']\n\n        if self.instance.username != data:\n            raise forms.ValidationError(_('Username does not match!'))\n\n        return data\n\n\nclass UserAdvertisingForm(forms.ModelForm):\n    class Meta(object):\n        model = UserProfile\n        fields = ['allow_ads']\n\n\nclass FacetField(forms.MultipleChoiceField):\n\n    \"\"\"\n    For filtering searches on a facet.\n\n    Has validation for the format of facet values.\n    \"\"\"\n\n    def valid_value(self, value):\n        \"\"\"\n        Although this is a choice field, no choices need to be supplied.\n\n        Instead, we just validate that the value is in the correct format for\n        facet filtering (facet_name:value)\n        \"\"\"\n        if ':' not in value:\n            return False\n        return True\n", "path": "readthedocs/core/forms.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Forms for core app.\"\"\"\n\nfrom __future__ import (\n    absolute_import, division, print_function, unicode_literals)\n\nimport logging\nfrom builtins import object\n\nfrom django import forms\nfrom django.contrib.auth.models import User\nfrom django.forms.fields import CharField\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom .models import UserProfile\n\nlog = logging.getLogger(__name__)\n\n\nclass UserProfileForm(forms.ModelForm):\n    first_name = CharField(label=_('First name'), required=False, max_length=30)\n    last_name = CharField(label=_('Last name'), required=False, max_length=30)\n\n    class Meta(object):\n        model = UserProfile\n        # Don't allow users edit someone else's user page\n        fields = ['first_name', 'last_name', 'homepage']\n\n    def __init__(self, *args, **kwargs):\n        super(UserProfileForm, self).__init__(*args, **kwargs)\n        try:\n            self.fields['first_name'].initial = self.instance.user.first_name\n            self.fields['last_name'].initial = self.instance.user.last_name\n        except AttributeError:\n            pass\n\n    def save(self, commit=True):\n        first_name = self.cleaned_data.pop('first_name', None)\n        last_name = self.cleaned_data.pop('last_name', None)\n        profile = super(UserProfileForm, self).save(commit=commit)\n        if commit:\n            user = profile.user\n            user.first_name = first_name\n            user.last_name = last_name\n            user.save()\n        return profile\n\n\nclass UserDeleteForm(forms.ModelForm):\n    username = CharField(\n        label=_('Username'),\n        help_text=_('Please type your username to confirm.'),\n    )\n\n    class Meta(object):\n        model = User\n        fields = ['username']\n\n    def clean_username(self):\n        data = self.cleaned_data['username']\n\n        if self.instance.username != data:\n            raise forms.ValidationError(_('Username does not match!'))\n\n        return data\n\n\nclass UserAdvertisingForm(forms.ModelForm):\n    class Meta(object):\n        model = UserProfile\n        fields = ['allow_ads']\n\n\nclass FacetField(forms.MultipleChoiceField):\n\n    \"\"\"\n    For filtering searches on a facet.\n\n    Has validation for the format of facet values.\n    \"\"\"\n\n    def valid_value(self, value):\n        \"\"\"\n        Although this is a choice field, no choices need to be supplied.\n\n        Instead, we just validate that the value is in the correct format for\n        facet filtering (facet_name:value)\n        \"\"\"\n        if ':' not in value:\n            return False\n        return True\n", "path": "readthedocs/core/forms.py"}]}