From b48d519e917cee7d8f6427a936638f66c1f1d02f Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Sun, 17 Dec 2023 10:28:39 -0500
Subject: [PATCH] Correct bug regarding ContextDict/ContextList handling

---
 .../mixins/response_mixin.py                   | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/django_expanded_test_cases/mixins/response_mixin.py b/django_expanded_test_cases/mixins/response_mixin.py
index 7a41d12..e472047 100644
--- a/django_expanded_test_cases/mixins/response_mixin.py
+++ b/django_expanded_test_cases/mixins/response_mixin.py
@@ -140,17 +140,33 @@ class ResponseTestCaseMixin(CoreTestCaseMixin):
             # Attempt to access key object. If fails, attempt to generate dict of values.
             try:
                 response_context.keys()
+
             except AttributeError:
                 # Handling for:
                 #     * django.template.context.RequestContext
                 #     * django.template.context.Context
-                # No guarantee this will work for other aribtrary types.
+                # No guarantee this will work for other arbitrary types.
                 # Handle as they come up.
                 temp_dict = {}
                 for context in response_context:
                     temp_dict = {**temp_dict, **context}
                 response_context = temp_dict
 
+            except Exception as err:
+                # Error occurred.
+                # Check if error is due to ContextDict/ContextList object being passed.
+                # Unsure why this happens, but seems to occur in tests that access Django 4.2.7 admin views?
+                # Needs further research. For now, this seems like enough to bypass it
+                # and have no immediately noticeable side effects.
+                from django.test.utils import ContextList
+                if isinstance(response_context, ContextList):
+                    # Skip output.
+                    return
+
+                else:
+                    # Raise original error.
+                    raise err
+
         self._debug_print()
         self._debug_print(
             '{0} {1} {0}'.format('=' * 10, 'response.context'),
-- 
GitLab