[error-report-web][PATCH 2/5] Avoid errors caused by attempting to update referrers for objects that don't exist.


Michael Halstead
 

From: Michael Halstead <mhalstead@linxufoundation.org>

---
Post/views.py | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/Post/views.py b/Post/views.py
index 5737076..0ad58ba 100644
--- a/Post/views.py
+++ b/Post/views.py
@@ -256,23 +256,23 @@ def search(request, mode=results_mode.LATEST, **kwargs):
items = items.order_by()
return render(request, "latest-errors.html", context)

-
def details(request, fail_id):
try:
build_failure = BuildFailure.objects.get(id=fail_id)
except ObjectDoesNotExist:
build_failure = None
- try:
- referer = urlparse(request.META['HTTP_REFERER'])
- referer_hostname = referer.hostname
- if referer.port:
- referer_hostname += ":" + str(referer.port)
- if referer_hostname != request.get_host():
- build_failure.REFERER = 'OTHER'
- except KeyError:
- # There is no referer
- build_failure.REFERER = 'NO_REFERER'
- build_failure.save()
+ if build_failure:
+ try:
+ referer = urlparse(request.META['HTTP_REFERER'])
+ referer_hostname = referer.hostname
+ if referer.port:
+ referer_hostname += ":" + str(referer.port)
+ if referer_hostname != request.get_host():
+ build_failure.REFERER = 'OTHER'
+ except KeyError:
+ # There is no referer
+ build_failure.REFERER = 'NO_REFERER'
+ build_failure.save()

context = {'detail' : build_failure, 'error_types' : ErrorType }

--
2.11.0