We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot save user profile with an empty zip code
## What kind of an issue is this?

- [x] Bug report

## What is the expected behaviour?

That you can save the form and receive guidance without having to input a ZIP code.

## What is the current behaviour?

If you don't have a ZIP code in the field the form doesn't validate and you get a runtime error, which doesn't tell the user why it didn't work.

## How do you reproduce this problem? 

Go to my profile, empty the ZIP code field and save.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/profiles/forms.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 import re
3 
4 from django import forms
5 from django.contrib import auth
6 from django.utils.translation import ugettext as _
7 
8 from apps.authentication.models import OnlineUser, Position
9 from apps.profiles.models import Privacy
10 
11 
12 class ProfileForm(forms.ModelForm):
13     class Meta(object):
14         model = OnlineUser
15 
16         fields = [
17             'nickname',
18             'website',
19             'phone_number',
20             'address',
21             'zip_code',
22             'allergies',
23             'compiled',
24             'bio',
25             'gender',
26             'github',
27             'linkedin'
28         ]
29         widgets = {
30             'allergies': forms.Textarea(attrs={'id': 'allergies'}),
31             'gender': forms.Select(attrs={'class': 'form-control', 'id': 'gender'}),
32             'bio': forms.Textarea(attrs={'id': 'bio'}),
33             'compiled': forms.CheckboxInput(attrs={'id': 'compiled'}),
34         }
35 
36     def clean(self):
37         super(ProfileForm, self).clean()
38 
39         cleaned_data = self.cleaned_data
40 
41         # ZIP code digits only
42         zip_code = cleaned_data['zip_code']
43         if len(zip_code) != 0 and not re.match(r'\d{4}', zip_code):
44             self._errors['zip_code'] = self.error_class([_("Postnummer må bestå av fire siffer.")])
45 
46         return cleaned_data
47 
48 
49 class PrivacyForm(forms.ModelForm):
50     class Meta(object):
51         model = Privacy
52         exclude = ['user', 'expose_nickname']
53 
54 
55 class MailSettingsForm(forms.ModelForm):
56     class Meta(object):
57         model = OnlineUser
58         fields = ['infomail', ]
59 
60 
61 class PositionForm(forms.ModelForm):
62     class Meta(object):
63         model = Position
64         exclude = ['user']
65         widgets = {
66             'committee': forms.Select(attrs={'class': 'form-control'}),
67             'position': forms.Select(attrs={'class': 'form-control'}),
68         }
69 
70     def clean(self):
71         super(PositionForm, self).clean()
72 
73         range_compiler = re.compile(r'\d{4}-\d{4}')
74         year_range = self.cleaned_data['period']
75 
76         # If it doesn't match the format YYYY-YYYY
77         if not range_compiler.match(year_range):
78             self._errors['period'] = self.error_class(
79                 [_('Feil format. Dobbelsjekk at input er på formatet YYYY-YYYY.')]
80             )
81             return self.cleaned_data
82 
83         years = year_range.split('-')
84 
85         # If somewhat they fucked up input, we don't want None-shit after the split.
86         if not years[0] or not years[1]:
87             self._errors['period'] = self.error_class([_('Feil format. Dobbelsjekk input.')])
88             return self.cleaned_data
89 
90         # If first year is larger than latter, or the diff is more than one, fail.
91         if (int(years[0]) > int(years[1])) or (int(years[1]) - int(years[0])) > 1:
92             self._errors['period'] = self.error_class([_('Ikke gyldig års-intervall. Bare ett år er tillat.')])
93 
94         return self.cleaned_data
95 
96 
97 class MembershipSettingsForm(forms.ModelForm):
98     def __init__(self, *args, **kwargs):
99         super(MembershipSettingsForm, self).__init__(*args, **kwargs)
100         self.fields['started_date'].widget.attrs['class'] = 'hasDatePicker'
101 
102     class Meta(object):
103         model = OnlineUser
104         fields = ['field_of_study', 'started_date']
105 
106         widgets = {
107             'started_date': forms.TextInput(attrs={'placeholder': 'YYYY-MM-DD'}),
108         }
109 
110 
111 class InternalServicesForm(forms.Form):
112     ow4_password = forms.CharField(widget=forms.PasswordInput(), label=_(u"Online passord"))
113     services_password = forms.CharField(widget=forms.PasswordInput(), label=_(u"Ønsket service passord"))
114     current_user = None
115 
116     def clean(self):
117         super(InternalServicesForm, self).clean()
118         if self.is_valid():
119             cleaned_data = self.cleaned_data
120 
121             # User object relation here
122             user = auth.authenticate(username=self.current_user.username, password=cleaned_data['ow4_password'])
123 
124             if user is None or user.id != self.current_user.id:
125                 self._errors['ow4_password'] = self.error_class([_(u"Passordet er ikke korrekt.")])
126 
127             return cleaned_data
128
```

Path: `apps/authentication/templatetags/gravatar_url_resolver.py`
Content:
```
1 import hashlib
2 import urllib
3 
4 from django import template
5 from django.conf import settings
6 
7 register = template.Library()
8 
9 
10 @register.assignment_tag(takes_context=True)
11 def gravatar_url(context, user, size):
12     prefix = "https://" if context['request'].is_secure() else "http://"
13     default = "%s%s%s_%s.png" % (
14         prefix,
15         context['request'].META['HTTP_HOST'],
16         settings.DEFAULT_PROFILE_PICTURE_PREFIX,
17         user.gender
18     )
19 
20     grav_url = "https://www.gravatar.com/avatar/" + hashlib.md5(user.email.encode()).hexdigest() + "?"
21     grav_url += urllib.parse.urlencode({'d': default, 's': str(size)})
22 
23     return grav_url
24
```
--- 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()

```

diff --git a/apps/authentication/templatetags/gravatar_url_resolver.py b/apps/authentication/templatetags/gravatar_url_resolver.py
--- a/apps/authentication/templatetags/gravatar_url_resolver.py
+++ b/apps/authentication/templatetags/gravatar_url_resolver.py
@@ -12,7 +12,7 @@
     prefix = "https://" if context['request'].is_secure() else "http://"
     default = "%s%s%s_%s.png" % (
         prefix,
-        context['request'].META['HTTP_HOST'],
+        context['request'].META.get('HTTP_HOST', 'localhost'),
         settings.DEFAULT_PROFILE_PICTURE_PREFIX,
         user.gender
     )
diff --git a/apps/profiles/forms.py b/apps/profiles/forms.py
--- a/apps/profiles/forms.py
+++ b/apps/profiles/forms.py
@@ -8,6 +8,8 @@
 from apps.authentication.models import OnlineUser, Position
 from apps.profiles.models import Privacy
 
+ZIP_CODE_VALIDATION_ERROR = "Postnummer må bestå av fire siffer."
+
 
 class ProfileForm(forms.ModelForm):
     class Meta(object):
@@ -33,17 +35,10 @@
             'compiled': forms.CheckboxInput(attrs={'id': 'compiled'}),
         }
 
-    def clean(self):
-        super(ProfileForm, self).clean()
-
-        cleaned_data = self.cleaned_data
-
-        # ZIP code digits only
-        zip_code = cleaned_data['zip_code']
-        if len(zip_code) != 0 and not re.match(r'\d{4}', zip_code):
-            self._errors['zip_code'] = self.error_class([_("Postnummer må bestå av fire siffer.")])
-
-        return cleaned_data
+    def clean_zip_code(self):
+        zip_code = self.cleaned_data['zip_code']
+        if zip_code and len(zip_code) != 0 and not re.match(r'\d{4}', zip_code):
+            self.add_error('zip_code', ZIP_CODE_VALIDATION_ERROR)
 
 
 class PrivacyForm(forms.ModelForm):

{"golden_diff": "diff --git a/apps/authentication/templatetags/gravatar_url_resolver.py b/apps/authentication/templatetags/gravatar_url_resolver.py\n--- a/apps/authentication/templatetags/gravatar_url_resolver.py\n+++ b/apps/authentication/templatetags/gravatar_url_resolver.py\n@@ -12,7 +12,7 @@\n     prefix = \"https://\" if context['request'].is_secure() else \"http://\"\n     default = \"%s%s%s_%s.png\" % (\n         prefix,\n-        context['request'].META['HTTP_HOST'],\n+        context['request'].META.get('HTTP_HOST', 'localhost'),\n         settings.DEFAULT_PROFILE_PICTURE_PREFIX,\n         user.gender\n     )\ndiff --git a/apps/profiles/forms.py b/apps/profiles/forms.py\n--- a/apps/profiles/forms.py\n+++ b/apps/profiles/forms.py\n@@ -8,6 +8,8 @@\n from apps.authentication.models import OnlineUser, Position\n from apps.profiles.models import Privacy\n \n+ZIP_CODE_VALIDATION_ERROR = \"Postnummer m\u00e5 best\u00e5 av fire siffer.\"\n+\n \n class ProfileForm(forms.ModelForm):\n     class Meta(object):\n@@ -33,17 +35,10 @@\n             'compiled': forms.CheckboxInput(attrs={'id': 'compiled'}),\n         }\n \n-    def clean(self):\n-        super(ProfileForm, self).clean()\n-\n-        cleaned_data = self.cleaned_data\n-\n-        # ZIP code digits only\n-        zip_code = cleaned_data['zip_code']\n-        if len(zip_code) != 0 and not re.match(r'\\d{4}', zip_code):\n-            self._errors['zip_code'] = self.error_class([_(\"Postnummer m\u00e5 best\u00e5 av fire siffer.\")])\n-\n-        return cleaned_data\n+    def clean_zip_code(self):\n+        zip_code = self.cleaned_data['zip_code']\n+        if zip_code and len(zip_code) != 0 and not re.match(r'\\d{4}', zip_code):\n+            self.add_error('zip_code', ZIP_CODE_VALIDATION_ERROR)\n \n \n class PrivacyForm(forms.ModelForm):\n", "issue": "Cannot save user profile with an empty zip code\n## What kind of an issue is this?\r\n\r\n- [x] Bug report\r\n\r\n## What is the expected behaviour?\r\n\r\nThat you can save the form and receive guidance without having to input a ZIP code.\r\n\r\n## What is the current behaviour?\r\n\r\nIf you don't have a ZIP code in the field the form doesn't validate and you get a runtime error, which doesn't tell the user why it didn't work.\r\n\r\n## How do you reproduce this problem? \r\n\r\nGo to my profile, empty the ZIP code field and save.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nimport re\n\nfrom django import forms\nfrom django.contrib import auth\nfrom django.utils.translation import ugettext as _\n\nfrom apps.authentication.models import OnlineUser, Position\nfrom apps.profiles.models import Privacy\n\n\nclass ProfileForm(forms.ModelForm):\n    class Meta(object):\n        model = OnlineUser\n\n        fields = [\n            'nickname',\n            'website',\n            'phone_number',\n            'address',\n            'zip_code',\n            'allergies',\n            'compiled',\n            'bio',\n            'gender',\n            'github',\n            'linkedin'\n        ]\n        widgets = {\n            'allergies': forms.Textarea(attrs={'id': 'allergies'}),\n            'gender': forms.Select(attrs={'class': 'form-control', 'id': 'gender'}),\n            'bio': forms.Textarea(attrs={'id': 'bio'}),\n            'compiled': forms.CheckboxInput(attrs={'id': 'compiled'}),\n        }\n\n    def clean(self):\n        super(ProfileForm, self).clean()\n\n        cleaned_data = self.cleaned_data\n\n        # ZIP code digits only\n        zip_code = cleaned_data['zip_code']\n        if len(zip_code) != 0 and not re.match(r'\\d{4}', zip_code):\n            self._errors['zip_code'] = self.error_class([_(\"Postnummer m\u00e5 best\u00e5 av fire siffer.\")])\n\n        return cleaned_data\n\n\nclass PrivacyForm(forms.ModelForm):\n    class Meta(object):\n        model = Privacy\n        exclude = ['user', 'expose_nickname']\n\n\nclass MailSettingsForm(forms.ModelForm):\n    class Meta(object):\n        model = OnlineUser\n        fields = ['infomail', ]\n\n\nclass PositionForm(forms.ModelForm):\n    class Meta(object):\n        model = Position\n        exclude = ['user']\n        widgets = {\n            'committee': forms.Select(attrs={'class': 'form-control'}),\n            'position': forms.Select(attrs={'class': 'form-control'}),\n        }\n\n    def clean(self):\n        super(PositionForm, self).clean()\n\n        range_compiler = re.compile(r'\\d{4}-\\d{4}')\n        year_range = self.cleaned_data['period']\n\n        # If it doesn't match the format YYYY-YYYY\n        if not range_compiler.match(year_range):\n            self._errors['period'] = self.error_class(\n                [_('Feil format. Dobbelsjekk at input er p\u00e5 formatet YYYY-YYYY.')]\n            )\n            return self.cleaned_data\n\n        years = year_range.split('-')\n\n        # If somewhat they fucked up input, we don't want None-shit after the split.\n        if not years[0] or not years[1]:\n            self._errors['period'] = self.error_class([_('Feil format. Dobbelsjekk input.')])\n            return self.cleaned_data\n\n        # If first year is larger than latter, or the diff is more than one, fail.\n        if (int(years[0]) > int(years[1])) or (int(years[1]) - int(years[0])) > 1:\n            self._errors['period'] = self.error_class([_('Ikke gyldig \u00e5rs-intervall. Bare ett \u00e5r er tillat.')])\n\n        return self.cleaned_data\n\n\nclass MembershipSettingsForm(forms.ModelForm):\n    def __init__(self, *args, **kwargs):\n        super(MembershipSettingsForm, self).__init__(*args, **kwargs)\n        self.fields['started_date'].widget.attrs['class'] = 'hasDatePicker'\n\n    class Meta(object):\n        model = OnlineUser\n        fields = ['field_of_study', 'started_date']\n\n        widgets = {\n            'started_date': forms.TextInput(attrs={'placeholder': 'YYYY-MM-DD'}),\n        }\n\n\nclass InternalServicesForm(forms.Form):\n    ow4_password = forms.CharField(widget=forms.PasswordInput(), label=_(u\"Online passord\"))\n    services_password = forms.CharField(widget=forms.PasswordInput(), label=_(u\"\u00d8nsket service passord\"))\n    current_user = None\n\n    def clean(self):\n        super(InternalServicesForm, self).clean()\n        if self.is_valid():\n            cleaned_data = self.cleaned_data\n\n            # User object relation here\n            user = auth.authenticate(username=self.current_user.username, password=cleaned_data['ow4_password'])\n\n            if user is None or user.id != self.current_user.id:\n                self._errors['ow4_password'] = self.error_class([_(u\"Passordet er ikke korrekt.\")])\n\n            return cleaned_data\n", "path": "apps/profiles/forms.py"}, {"content": "import hashlib\nimport urllib\n\nfrom django import template\nfrom django.conf import settings\n\nregister = template.Library()\n\n\n@register.assignment_tag(takes_context=True)\ndef gravatar_url(context, user, size):\n    prefix = \"https://\" if context['request'].is_secure() else \"http://\"\n    default = \"%s%s%s_%s.png\" % (\n        prefix,\n        context['request'].META['HTTP_HOST'],\n        settings.DEFAULT_PROFILE_PICTURE_PREFIX,\n        user.gender\n    )\n\n    grav_url = \"https://www.gravatar.com/avatar/\" + hashlib.md5(user.email.encode()).hexdigest() + \"?\"\n    grav_url += urllib.parse.urlencode({'d': default, 's': str(size)})\n\n    return grav_url\n", "path": "apps/authentication/templatetags/gravatar_url_resolver.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nimport re\n\nfrom django import forms\nfrom django.contrib import auth\nfrom django.utils.translation import ugettext as _\n\nfrom apps.authentication.models import OnlineUser, Position\nfrom apps.profiles.models import Privacy\n\nZIP_CODE_VALIDATION_ERROR = \"Postnummer m\u00e5 best\u00e5 av fire siffer.\"\n\n\nclass ProfileForm(forms.ModelForm):\n    class Meta(object):\n        model = OnlineUser\n\n        fields = [\n            'nickname',\n            'website',\n            'phone_number',\n            'address',\n            'zip_code',\n            'allergies',\n            'compiled',\n            'bio',\n            'gender',\n            'github',\n            'linkedin'\n        ]\n        widgets = {\n            'allergies': forms.Textarea(attrs={'id': 'allergies'}),\n            'gender': forms.Select(attrs={'class': 'form-control', 'id': 'gender'}),\n            'bio': forms.Textarea(attrs={'id': 'bio'}),\n            'compiled': forms.CheckboxInput(attrs={'id': 'compiled'}),\n        }\n\n    def clean_zip_code(self):\n        zip_code = self.cleaned_data['zip_code']\n        if zip_code and len(zip_code) != 0 and not re.match(r'\\d{4}', zip_code):\n            self.add_error('zip_code', ZIP_CODE_VALIDATION_ERROR)\n\n\nclass PrivacyForm(forms.ModelForm):\n    class Meta(object):\n        model = Privacy\n        exclude = ['user', 'expose_nickname']\n\n\nclass MailSettingsForm(forms.ModelForm):\n    class Meta(object):\n        model = OnlineUser\n        fields = ['infomail', ]\n\n\nclass PositionForm(forms.ModelForm):\n    class Meta(object):\n        model = Position\n        exclude = ['user']\n        widgets = {\n            'committee': forms.Select(attrs={'class': 'form-control'}),\n            'position': forms.Select(attrs={'class': 'form-control'}),\n        }\n\n    def clean(self):\n        super(PositionForm, self).clean()\n\n        range_compiler = re.compile(r'\\d{4}-\\d{4}')\n        year_range = self.cleaned_data['period']\n\n        # If it doesn't match the format YYYY-YYYY\n        if not range_compiler.match(year_range):\n            self._errors['period'] = self.error_class(\n                [_('Feil format. Dobbelsjekk at input er p\u00e5 formatet YYYY-YYYY.')]\n            )\n            return self.cleaned_data\n\n        years = year_range.split('-')\n\n        # If somewhat they fucked up input, we don't want None-shit after the split.\n        if not years[0] or not years[1]:\n            self._errors['period'] = self.error_class([_('Feil format. Dobbelsjekk input.')])\n            return self.cleaned_data\n\n        # If first year is larger than latter, or the diff is more than one, fail.\n        if (int(years[0]) > int(years[1])) or (int(years[1]) - int(years[0])) > 1:\n            self._errors['period'] = self.error_class([_('Ikke gyldig \u00e5rs-intervall. Bare ett \u00e5r er tillat.')])\n\n        return self.cleaned_data\n\n\nclass MembershipSettingsForm(forms.ModelForm):\n    def __init__(self, *args, **kwargs):\n        super(MembershipSettingsForm, self).__init__(*args, **kwargs)\n        self.fields['started_date'].widget.attrs['class'] = 'hasDatePicker'\n\n    class Meta(object):\n        model = OnlineUser\n        fields = ['field_of_study', 'started_date']\n\n        widgets = {\n            'started_date': forms.TextInput(attrs={'placeholder': 'YYYY-MM-DD'}),\n        }\n\n\nclass InternalServicesForm(forms.Form):\n    ow4_password = forms.CharField(widget=forms.PasswordInput(), label=_(u\"Online passord\"))\n    services_password = forms.CharField(widget=forms.PasswordInput(), label=_(u\"\u00d8nsket service passord\"))\n    current_user = None\n\n    def clean(self):\n        super(InternalServicesForm, self).clean()\n        if self.is_valid():\n            cleaned_data = self.cleaned_data\n\n            # User object relation here\n            user = auth.authenticate(username=self.current_user.username, password=cleaned_data['ow4_password'])\n\n            if user is None or user.id != self.current_user.id:\n                self._errors['ow4_password'] = self.error_class([_(u\"Passordet er ikke korrekt.\")])\n\n            return cleaned_data\n", "path": "apps/profiles/forms.py"}, {"content": "import hashlib\nimport urllib\n\nfrom django import template\nfrom django.conf import settings\n\nregister = template.Library()\n\n\n@register.assignment_tag(takes_context=True)\ndef gravatar_url(context, user, size):\n    prefix = \"https://\" if context['request'].is_secure() else \"http://\"\n    default = \"%s%s%s_%s.png\" % (\n        prefix,\n        context['request'].META.get('HTTP_HOST', 'localhost'),\n        settings.DEFAULT_PROFILE_PICTURE_PREFIX,\n        user.gender\n    )\n\n    grav_url = \"https://www.gravatar.com/avatar/\" + hashlib.md5(user.email.encode()).hexdigest() + \"?\"\n    grav_url += urllib.parse.urlencode({'d': default, 's': str(size)})\n\n    return grav_url\n", "path": "apps/authentication/templatetags/gravatar_url_resolver.py"}]}