diff --git a/src/djangooidc/views.py b/src/djangooidc/views.py index 2d7131d50..8e112769b 100644 --- a/src/djangooidc/views.py +++ b/src/djangooidc/views.py @@ -50,13 +50,13 @@ def error_page(request, error): """Display a sensible message and log the error.""" logger.error(error) if isinstance(error, o_e.AuthenticationFailed): - context={ + context = { "friendly_message": error.friendly_message, "log_identifier": error.locator, } return custom_401_error_view(request, context) if isinstance(error, o_e.InternalError): - context={ + context = { "friendly_message": error.friendly_message, "log_identifier": error.locator, } diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index 058fc720c..c743aed0c 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -3,7 +3,7 @@ For more information see: https://docs.djangoproject.com/en/4.0/topics/http/urls/ """ -from django.conf.urls import handler500 + from django.contrib import admin from django.urls import include, path from django.views.generic import RedirectView @@ -151,6 +151,14 @@ urlpatterns = [ # Djangooidc strips out context data from that context, so we define a custom error # view through this method. +# If Djangooidc is left to its own devices and uses reverse directly, +# then both context and session information will be obliterated due to: + +# a) Djangooidc being out of scope for context_processors +# b) Potential cyclical import errors restricting what kind of data is passable. + +# Rather than dealing with that, we keep everything centralized in one location. +# This way, we can share a view for djangooidc, and other pages as we see fit. handler500 = "registrar.views.utility.error_views.custom_500_error_view" # we normally would guard these with `if settings.DEBUG` but tests run with diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index fa499893c..079fce3bc 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -325,7 +325,6 @@ class Domain(TimeStampedModel, DomainHelper): Subordinate hosts (something.your-domain.gov) MUST have IP addresses, while non-subordinate hosts MUST NOT. """ - raise ValueError("test") try: # attempt to retrieve hosts from registry and store in cache and db hosts = self._get_property("hosts") diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 053281e99..b8055f288 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -6,7 +6,7 @@ from registrar.models.domain import Domain from registrar.models.user_domain_role import UserDomainRole from registrar.views.domain import DomainNameserversView -from .common import MockEppLib, less_console_noise # type: ignore +from .common import MockEppLib # type: ignore from unittest.mock import patch from django.urls import reverse @@ -135,4 +135,3 @@ class TestEnvironmentVariablesEffects(TestCase): self.assertEqual(contact_page_500.status_code, 500) self.assertNotContains(contact_page_500, "You are on a test site.") - diff --git a/src/registrar/views/utility/error_views.py b/src/registrar/views/utility/error_views.py index c7841911c..48ae628a4 100644 --- a/src/registrar/views/utility/error_views.py +++ b/src/registrar/views/utility/error_views.py @@ -1,6 +1,21 @@ -"""Custom views that allow for error view customization""" +""" +Custom views that allow for error view customization. + +Used as a general handler for 500 errors both coming from the registrar app, but +also the djangooidc app. + +If Djangooidc is left to its own devices and uses reverse directly, +then both context and session information will be obliterated due to: + +a) Djangooidc being out of scope for context_processors +b) Potential cyclical import errors restricting what kind of data is passable. + +Rather than dealing with that, we keep everything centralized in one location. +""" + from django.shortcuts import render + def custom_500_error_view(request, context=None): """Used to redirect 500 errors to a custom view""" if context is None: @@ -8,6 +23,7 @@ def custom_500_error_view(request, context=None): else: return render(request, "500.html", context=context, status=500) + def custom_401_error_view(request, context=None): """Used to redirect 401 errors to a custom view""" if context is None: diff --git a/src/registrar/views/utility/permission_views.py b/src/registrar/views/utility/permission_views.py index 8f0b8e0d1..f2752c3b5 100644 --- a/src/registrar/views/utility/permission_views.py +++ b/src/registrar/views/utility/permission_views.py @@ -2,7 +2,6 @@ import abc # abstract base class -from django.conf import settings from django.views.generic import DetailView, DeleteView, TemplateView from registrar.models import Domain, DomainRequest, DomainInvitation from registrar.models.user_domain_role import UserDomainRole