We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Click twice in the 404 sustainability link doesn't work
## Steps to reproduce it

1. Go to https://readthedocs.org/humitos
2. You will see a 404 page with a sustainability link (https://readthedocs.org/sustainability/click/90/EdfO7Jed1YQr/)
3. Click on it
4. It goes to Sentry home page
5. Go back and click it again

## Expected Result

Go to Sentry again.

## Actual Result

You get **a new** 404 page with a new link :)


--- 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/donate/views.py`
Content:
```
1 """Donation views"""
2 # We use 'hash' heavily in the API here.
3 # pylint: disable=redefined-builtin
4 
5 from __future__ import absolute_import
6 import logging
7 
8 from django.views.generic import TemplateView
9 from django.core.urlresolvers import reverse
10 from django.utils.translation import ugettext_lazy as _
11 from django.shortcuts import redirect, get_object_or_404, render_to_response
12 from django.template import RequestContext
13 from django.core.cache import cache
14 from django.http import Http404
15 
16 from vanilla import CreateView, ListView
17 
18 from readthedocs.donate.utils import offer_promo
19 from readthedocs.payments.mixins import StripeMixin
20 from readthedocs.projects.models import Project
21 from readthedocs.redirects.utils import get_redirect_response
22 
23 from .models import Supporter, SupporterPromo
24 from .constants import CLICKS, VIEWS
25 from .forms import SupporterForm, EthicalAdForm
26 from .mixins import DonateProgressMixin
27 
28 log = logging.getLogger(__name__)
29 
30 
31 class PayAdsView(StripeMixin, CreateView):
32 
33     """Create a payment locally and in Stripe"""
34 
35     form_class = EthicalAdForm
36     success_message = _('Your payment has been received')
37     template_name = 'donate/ethicalads.html'
38 
39     def get_success_url(self):
40         return reverse('pay_success')
41 
42 
43 class PaySuccess(TemplateView):
44     template_name = 'donate/ethicalads-success.html'
45 
46 
47 class DonateCreateView(StripeMixin, CreateView):
48 
49     """Create a donation locally and in Stripe"""
50 
51     form_class = SupporterForm
52     success_message = _('Your contribution has been received')
53     template_name = 'donate/create.html'
54 
55     def get_success_url(self):
56         return reverse('donate_success')
57 
58     def get_initial(self):
59         return {'dollars': self.request.GET.get('dollars', 50)}
60 
61     def get_form(self, data=None, files=None, **kwargs):
62         kwargs['user'] = self.request.user
63         return super(DonateCreateView, self).get_form(data, files, **kwargs)
64 
65 
66 class DonateSuccessView(TemplateView):
67     template_name = 'donate/success.html'
68 
69 
70 class DonateListView(DonateProgressMixin, ListView):
71 
72     """Donation list and detail view"""
73 
74     template_name = 'donate/list.html'
75     model = Supporter
76     context_object_name = 'supporters'
77 
78     def get_queryset(self):
79         return (Supporter.objects
80                 .filter(public=True)
81                 .order_by('-dollars', '-pub_date'))
82 
83     def get_template_names(self):
84         return [self.template_name]
85 
86 
87 class PromoDetailView(TemplateView):
88     template_name = 'donate/promo_detail.html'
89 
90     def get_context_data(self, **kwargs):
91         promo_slug = kwargs['promo_slug']
92         days = int(self.request.GET.get('days', 90))
93 
94         if promo_slug == 'live' and self.request.user.is_staff:
95             promos = SupporterPromo.objects.filter(live=True)
96         elif promo_slug[-1] == '*' and '-' in promo_slug:
97             promos = SupporterPromo.objects.filter(
98                 analytics_id__contains=promo_slug.replace('*', '')
99             )
100         else:
101             slugs = promo_slug.split(',')
102             promos = SupporterPromo.objects.filter(analytics_id__in=slugs)
103 
104         total_clicks = sum(promo.total_clicks() for promo in promos)
105 
106         return {
107             'promos': promos,
108             'total_clicks': total_clicks,
109             'days': days,
110             'days_slice': ':%s' % days,
111         }
112 
113 
114 def click_proxy(request, promo_id, hash):
115     """Track a click on a promotion and redirect to the link."""
116     promo = get_object_or_404(SupporterPromo, pk=promo_id)
117     count = cache.get(promo.cache_key(type=CLICKS, hash=hash), None)
118     if count is None:
119         log.warning('Old or nonexistent hash tried on Click.')
120     elif count == 0:
121         promo.incr(CLICKS)
122         cache.incr(promo.cache_key(type=CLICKS, hash=hash))
123         project_slug = cache.get(
124             promo.cache_key(type='project', hash=hash),
125             None
126         )
127         if project_slug:
128             project = Project.objects.get(slug=project_slug)
129             promo.incr(CLICKS, project=project)
130     else:
131         agent = request.META.get('HTTP_USER_AGENT', 'Unknown')
132         log.warning(
133             'Duplicate click logged. {count} total clicks tried. User Agent: [{agent}]'.format(
134                 count=count, agent=agent
135             )
136         )
137         cache.incr(promo.cache_key(type=CLICKS, hash=hash))
138         raise Http404('Invalid click. This has been logged.')
139     return redirect(promo.link)
140 
141 
142 def view_proxy(request, promo_id, hash):
143     """Track a view of a promotion and redirect to the image."""
144     promo = get_object_or_404(SupporterPromo, pk=promo_id)
145     if not promo.image:
146         raise Http404('No image defined for this promo.')
147     count = cache.get(promo.cache_key(type=VIEWS, hash=hash), None)
148     if count is None:
149         log.warning('Old or nonexistent hash tried on View.')
150     elif count == 0:
151         promo.incr(VIEWS)
152         cache.incr(promo.cache_key(type=VIEWS, hash=hash))
153         project_slug = cache.get(
154             promo.cache_key(type='project', hash=hash),
155             None
156         )
157         if project_slug:
158             project = Project.objects.get(slug=project_slug)
159             promo.incr(VIEWS, project=project)
160     else:
161         agent = request.META.get('HTTP_USER_AGENT', 'Unknown')
162         log.warning(
163             'Duplicate view logged. {count} total views tried. User Agent: [{agent}]'.format(
164                 count=count, agent=agent
165             )
166         )
167         cache.incr(promo.cache_key(type=VIEWS, hash=hash))
168         raise Http404('Invalid click. This has been logged.')
169     return redirect(promo.image)
170 
171 
172 def _add_promo_data(display_type):
173     promo_queryset = SupporterPromo.objects.filter(live=True, display_type=display_type)
174     promo_obj = promo_queryset.order_by('?').first()
175     if promo_obj:
176         promo_dict = offer_promo(promo_obj=promo_obj, project=None)
177     else:
178         promo_dict = None
179     return promo_dict
180 
181 
182 def promo_500(request, template_name='donate/promo_500.html', **__):
183     """A simple 500 handler so we get media"""
184     promo_dict = _add_promo_data(display_type='error')
185     r = render_to_response(template_name,
186                            context_instance=RequestContext(request),
187                            context={
188                                'promo_data': promo_dict,
189                            })
190     r.status_code = 500
191     return r
192 
193 
194 def promo_404(request, template_name='donate/promo_404.html', **__):
195     """A simple 404 handler so we get media"""
196     promo_dict = _add_promo_data(display_type='error')
197     response = get_redirect_response(request, path=request.get_full_path())
198     if response:
199         return response
200     r = render_to_response(template_name,
201                            context_instance=RequestContext(request),
202                            context={
203                                'promo_data': promo_dict,
204                            })
205     r.status_code = 404
206     return r
207
```
--- 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/readthedocs/donate/views.py b/readthedocs/donate/views.py
--- a/readthedocs/donate/views.py
+++ b/readthedocs/donate/views.py
@@ -135,7 +135,6 @@
             )
         )
         cache.incr(promo.cache_key(type=CLICKS, hash=hash))
-        raise Http404('Invalid click. This has been logged.')
     return redirect(promo.link)
 
 
@@ -165,7 +164,6 @@
             )
         )
         cache.incr(promo.cache_key(type=VIEWS, hash=hash))
-        raise Http404('Invalid click. This has been logged.')
     return redirect(promo.image)

{"golden_diff": "diff --git a/readthedocs/donate/views.py b/readthedocs/donate/views.py\n--- a/readthedocs/donate/views.py\n+++ b/readthedocs/donate/views.py\n@@ -135,7 +135,6 @@\n             )\n         )\n         cache.incr(promo.cache_key(type=CLICKS, hash=hash))\n-        raise Http404('Invalid click. This has been logged.')\n     return redirect(promo.link)\n \n \n@@ -165,7 +164,6 @@\n             )\n         )\n         cache.incr(promo.cache_key(type=VIEWS, hash=hash))\n-        raise Http404('Invalid click. This has been logged.')\n     return redirect(promo.image)\n", "issue": "Click twice in the 404 sustainability link doesn't work\n## Steps to reproduce it\r\n\r\n1. Go to https://readthedocs.org/humitos\r\n2. You will see a 404 page with a sustainability link (https://readthedocs.org/sustainability/click/90/EdfO7Jed1YQr/)\r\n3. Click on it\r\n4. It goes to Sentry home page\r\n5. Go back and click it again\r\n\r\n## Expected Result\r\n\r\nGo to Sentry again.\r\n\r\n## Actual Result\r\n\r\nYou get **a new** 404 page with a new link :)\r\n\n", "before_files": [{"content": "\"\"\"Donation views\"\"\"\n# We use 'hash' heavily in the API here.\n# pylint: disable=redefined-builtin\n\nfrom __future__ import absolute_import\nimport logging\n\nfrom django.views.generic import TemplateView\nfrom django.core.urlresolvers import reverse\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.shortcuts import redirect, get_object_or_404, render_to_response\nfrom django.template import RequestContext\nfrom django.core.cache import cache\nfrom django.http import Http404\n\nfrom vanilla import CreateView, ListView\n\nfrom readthedocs.donate.utils import offer_promo\nfrom readthedocs.payments.mixins import StripeMixin\nfrom readthedocs.projects.models import Project\nfrom readthedocs.redirects.utils import get_redirect_response\n\nfrom .models import Supporter, SupporterPromo\nfrom .constants import CLICKS, VIEWS\nfrom .forms import SupporterForm, EthicalAdForm\nfrom .mixins import DonateProgressMixin\n\nlog = logging.getLogger(__name__)\n\n\nclass PayAdsView(StripeMixin, CreateView):\n\n    \"\"\"Create a payment locally and in Stripe\"\"\"\n\n    form_class = EthicalAdForm\n    success_message = _('Your payment has been received')\n    template_name = 'donate/ethicalads.html'\n\n    def get_success_url(self):\n        return reverse('pay_success')\n\n\nclass PaySuccess(TemplateView):\n    template_name = 'donate/ethicalads-success.html'\n\n\nclass DonateCreateView(StripeMixin, CreateView):\n\n    \"\"\"Create a donation locally and in Stripe\"\"\"\n\n    form_class = SupporterForm\n    success_message = _('Your contribution has been received')\n    template_name = 'donate/create.html'\n\n    def get_success_url(self):\n        return reverse('donate_success')\n\n    def get_initial(self):\n        return {'dollars': self.request.GET.get('dollars', 50)}\n\n    def get_form(self, data=None, files=None, **kwargs):\n        kwargs['user'] = self.request.user\n        return super(DonateCreateView, self).get_form(data, files, **kwargs)\n\n\nclass DonateSuccessView(TemplateView):\n    template_name = 'donate/success.html'\n\n\nclass DonateListView(DonateProgressMixin, ListView):\n\n    \"\"\"Donation list and detail view\"\"\"\n\n    template_name = 'donate/list.html'\n    model = Supporter\n    context_object_name = 'supporters'\n\n    def get_queryset(self):\n        return (Supporter.objects\n                .filter(public=True)\n                .order_by('-dollars', '-pub_date'))\n\n    def get_template_names(self):\n        return [self.template_name]\n\n\nclass PromoDetailView(TemplateView):\n    template_name = 'donate/promo_detail.html'\n\n    def get_context_data(self, **kwargs):\n        promo_slug = kwargs['promo_slug']\n        days = int(self.request.GET.get('days', 90))\n\n        if promo_slug == 'live' and self.request.user.is_staff:\n            promos = SupporterPromo.objects.filter(live=True)\n        elif promo_slug[-1] == '*' and '-' in promo_slug:\n            promos = SupporterPromo.objects.filter(\n                analytics_id__contains=promo_slug.replace('*', '')\n            )\n        else:\n            slugs = promo_slug.split(',')\n            promos = SupporterPromo.objects.filter(analytics_id__in=slugs)\n\n        total_clicks = sum(promo.total_clicks() for promo in promos)\n\n        return {\n            'promos': promos,\n            'total_clicks': total_clicks,\n            'days': days,\n            'days_slice': ':%s' % days,\n        }\n\n\ndef click_proxy(request, promo_id, hash):\n    \"\"\"Track a click on a promotion and redirect to the link.\"\"\"\n    promo = get_object_or_404(SupporterPromo, pk=promo_id)\n    count = cache.get(promo.cache_key(type=CLICKS, hash=hash), None)\n    if count is None:\n        log.warning('Old or nonexistent hash tried on Click.')\n    elif count == 0:\n        promo.incr(CLICKS)\n        cache.incr(promo.cache_key(type=CLICKS, hash=hash))\n        project_slug = cache.get(\n            promo.cache_key(type='project', hash=hash),\n            None\n        )\n        if project_slug:\n            project = Project.objects.get(slug=project_slug)\n            promo.incr(CLICKS, project=project)\n    else:\n        agent = request.META.get('HTTP_USER_AGENT', 'Unknown')\n        log.warning(\n            'Duplicate click logged. {count} total clicks tried. User Agent: [{agent}]'.format(\n                count=count, agent=agent\n            )\n        )\n        cache.incr(promo.cache_key(type=CLICKS, hash=hash))\n        raise Http404('Invalid click. This has been logged.')\n    return redirect(promo.link)\n\n\ndef view_proxy(request, promo_id, hash):\n    \"\"\"Track a view of a promotion and redirect to the image.\"\"\"\n    promo = get_object_or_404(SupporterPromo, pk=promo_id)\n    if not promo.image:\n        raise Http404('No image defined for this promo.')\n    count = cache.get(promo.cache_key(type=VIEWS, hash=hash), None)\n    if count is None:\n        log.warning('Old or nonexistent hash tried on View.')\n    elif count == 0:\n        promo.incr(VIEWS)\n        cache.incr(promo.cache_key(type=VIEWS, hash=hash))\n        project_slug = cache.get(\n            promo.cache_key(type='project', hash=hash),\n            None\n        )\n        if project_slug:\n            project = Project.objects.get(slug=project_slug)\n            promo.incr(VIEWS, project=project)\n    else:\n        agent = request.META.get('HTTP_USER_AGENT', 'Unknown')\n        log.warning(\n            'Duplicate view logged. {count} total views tried. User Agent: [{agent}]'.format(\n                count=count, agent=agent\n            )\n        )\n        cache.incr(promo.cache_key(type=VIEWS, hash=hash))\n        raise Http404('Invalid click. This has been logged.')\n    return redirect(promo.image)\n\n\ndef _add_promo_data(display_type):\n    promo_queryset = SupporterPromo.objects.filter(live=True, display_type=display_type)\n    promo_obj = promo_queryset.order_by('?').first()\n    if promo_obj:\n        promo_dict = offer_promo(promo_obj=promo_obj, project=None)\n    else:\n        promo_dict = None\n    return promo_dict\n\n\ndef promo_500(request, template_name='donate/promo_500.html', **__):\n    \"\"\"A simple 500 handler so we get media\"\"\"\n    promo_dict = _add_promo_data(display_type='error')\n    r = render_to_response(template_name,\n                           context_instance=RequestContext(request),\n                           context={\n                               'promo_data': promo_dict,\n                           })\n    r.status_code = 500\n    return r\n\n\ndef promo_404(request, template_name='donate/promo_404.html', **__):\n    \"\"\"A simple 404 handler so we get media\"\"\"\n    promo_dict = _add_promo_data(display_type='error')\n    response = get_redirect_response(request, path=request.get_full_path())\n    if response:\n        return response\n    r = render_to_response(template_name,\n                           context_instance=RequestContext(request),\n                           context={\n                               'promo_data': promo_dict,\n                           })\n    r.status_code = 404\n    return r\n", "path": "readthedocs/donate/views.py"}], "after_files": [{"content": "\"\"\"Donation views\"\"\"\n# We use 'hash' heavily in the API here.\n# pylint: disable=redefined-builtin\n\nfrom __future__ import absolute_import\nimport logging\n\nfrom django.views.generic import TemplateView\nfrom django.core.urlresolvers import reverse\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.shortcuts import redirect, get_object_or_404, render_to_response\nfrom django.template import RequestContext\nfrom django.core.cache import cache\nfrom django.http import Http404\n\nfrom vanilla import CreateView, ListView\n\nfrom readthedocs.donate.utils import offer_promo\nfrom readthedocs.payments.mixins import StripeMixin\nfrom readthedocs.projects.models import Project\nfrom readthedocs.redirects.utils import get_redirect_response\n\nfrom .models import Supporter, SupporterPromo\nfrom .constants import CLICKS, VIEWS\nfrom .forms import SupporterForm, EthicalAdForm\nfrom .mixins import DonateProgressMixin\n\nlog = logging.getLogger(__name__)\n\n\nclass PayAdsView(StripeMixin, CreateView):\n\n    \"\"\"Create a payment locally and in Stripe\"\"\"\n\n    form_class = EthicalAdForm\n    success_message = _('Your payment has been received')\n    template_name = 'donate/ethicalads.html'\n\n    def get_success_url(self):\n        return reverse('pay_success')\n\n\nclass PaySuccess(TemplateView):\n    template_name = 'donate/ethicalads-success.html'\n\n\nclass DonateCreateView(StripeMixin, CreateView):\n\n    \"\"\"Create a donation locally and in Stripe\"\"\"\n\n    form_class = SupporterForm\n    success_message = _('Your contribution has been received')\n    template_name = 'donate/create.html'\n\n    def get_success_url(self):\n        return reverse('donate_success')\n\n    def get_initial(self):\n        return {'dollars': self.request.GET.get('dollars', 50)}\n\n    def get_form(self, data=None, files=None, **kwargs):\n        kwargs['user'] = self.request.user\n        return super(DonateCreateView, self).get_form(data, files, **kwargs)\n\n\nclass DonateSuccessView(TemplateView):\n    template_name = 'donate/success.html'\n\n\nclass DonateListView(DonateProgressMixin, ListView):\n\n    \"\"\"Donation list and detail view\"\"\"\n\n    template_name = 'donate/list.html'\n    model = Supporter\n    context_object_name = 'supporters'\n\n    def get_queryset(self):\n        return (Supporter.objects\n                .filter(public=True)\n                .order_by('-dollars', '-pub_date'))\n\n    def get_template_names(self):\n        return [self.template_name]\n\n\nclass PromoDetailView(TemplateView):\n    template_name = 'donate/promo_detail.html'\n\n    def get_context_data(self, **kwargs):\n        promo_slug = kwargs['promo_slug']\n        days = int(self.request.GET.get('days', 90))\n\n        if promo_slug == 'live' and self.request.user.is_staff:\n            promos = SupporterPromo.objects.filter(live=True)\n        elif promo_slug[-1] == '*' and '-' in promo_slug:\n            promos = SupporterPromo.objects.filter(\n                analytics_id__contains=promo_slug.replace('*', '')\n            )\n        else:\n            slugs = promo_slug.split(',')\n            promos = SupporterPromo.objects.filter(analytics_id__in=slugs)\n\n        total_clicks = sum(promo.total_clicks() for promo in promos)\n\n        return {\n            'promos': promos,\n            'total_clicks': total_clicks,\n            'days': days,\n            'days_slice': ':%s' % days,\n        }\n\n\ndef click_proxy(request, promo_id, hash):\n    \"\"\"Track a click on a promotion and redirect to the link.\"\"\"\n    promo = get_object_or_404(SupporterPromo, pk=promo_id)\n    count = cache.get(promo.cache_key(type=CLICKS, hash=hash), None)\n    if count is None:\n        log.warning('Old or nonexistent hash tried on Click.')\n    elif count == 0:\n        promo.incr(CLICKS)\n        cache.incr(promo.cache_key(type=CLICKS, hash=hash))\n        project_slug = cache.get(\n            promo.cache_key(type='project', hash=hash),\n            None\n        )\n        if project_slug:\n            project = Project.objects.get(slug=project_slug)\n            promo.incr(CLICKS, project=project)\n    else:\n        agent = request.META.get('HTTP_USER_AGENT', 'Unknown')\n        log.warning(\n            'Duplicate click logged. {count} total clicks tried. User Agent: [{agent}]'.format(\n                count=count, agent=agent\n            )\n        )\n        cache.incr(promo.cache_key(type=CLICKS, hash=hash))\n    return redirect(promo.link)\n\n\ndef view_proxy(request, promo_id, hash):\n    \"\"\"Track a view of a promotion and redirect to the image.\"\"\"\n    promo = get_object_or_404(SupporterPromo, pk=promo_id)\n    if not promo.image:\n        raise Http404('No image defined for this promo.')\n    count = cache.get(promo.cache_key(type=VIEWS, hash=hash), None)\n    if count is None:\n        log.warning('Old or nonexistent hash tried on View.')\n    elif count == 0:\n        promo.incr(VIEWS)\n        cache.incr(promo.cache_key(type=VIEWS, hash=hash))\n        project_slug = cache.get(\n            promo.cache_key(type='project', hash=hash),\n            None\n        )\n        if project_slug:\n            project = Project.objects.get(slug=project_slug)\n            promo.incr(VIEWS, project=project)\n    else:\n        agent = request.META.get('HTTP_USER_AGENT', 'Unknown')\n        log.warning(\n            'Duplicate view logged. {count} total views tried. User Agent: [{agent}]'.format(\n                count=count, agent=agent\n            )\n        )\n        cache.incr(promo.cache_key(type=VIEWS, hash=hash))\n    return redirect(promo.image)\n\n\ndef _add_promo_data(display_type):\n    promo_queryset = SupporterPromo.objects.filter(live=True, display_type=display_type)\n    promo_obj = promo_queryset.order_by('?').first()\n    if promo_obj:\n        promo_dict = offer_promo(promo_obj=promo_obj, project=None)\n    else:\n        promo_dict = None\n    return promo_dict\n\n\ndef promo_500(request, template_name='donate/promo_500.html', **__):\n    \"\"\"A simple 500 handler so we get media\"\"\"\n    promo_dict = _add_promo_data(display_type='error')\n    r = render_to_response(template_name,\n                           context_instance=RequestContext(request),\n                           context={\n                               'promo_data': promo_dict,\n                           })\n    r.status_code = 500\n    return r\n\n\ndef promo_404(request, template_name='donate/promo_404.html', **__):\n    \"\"\"A simple 404 handler so we get media\"\"\"\n    promo_dict = _add_promo_data(display_type='error')\n    response = get_redirect_response(request, path=request.get_full_path())\n    if response:\n        return response\n    r = render_to_response(template_name,\n                           context_instance=RequestContext(request),\n                           context={\n                               'promo_data': promo_dict,\n                           })\n    r.status_code = 404\n    return r\n", "path": "readthedocs/donate/views.py"}]}