mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #19827 -- Kept stacktrace in defaulttags exception reraising
Thanks Kronuz for the report and the initial patch.
This commit is contained in:
		
				
					committed by
					
						 Claude Paroz
						Claude Paroz
					
				
			
			
				
	
			
			
			
						parent
						
							0ad76843b5
						
					
				
				
					commit
					687d2e967d
				
			| @@ -416,7 +416,8 @@ class URLNode(Node): | |||||||
|         url = '' |         url = '' | ||||||
|         try: |         try: | ||||||
|             url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) |             url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) | ||||||
|         except NoReverseMatch as e: |         except NoReverseMatch: | ||||||
|  |             exc_info = sys.exc_info() | ||||||
|             if settings.SETTINGS_MODULE: |             if settings.SETTINGS_MODULE: | ||||||
|                 project_name = settings.SETTINGS_MODULE.split('.')[0] |                 project_name = settings.SETTINGS_MODULE.split('.')[0] | ||||||
|                 try: |                 try: | ||||||
| @@ -428,10 +429,10 @@ class URLNode(Node): | |||||||
|                         # Re-raise the original exception, not the one with |                         # Re-raise the original exception, not the one with | ||||||
|                         # the path relative to the project. This makes a |                         # the path relative to the project. This makes a | ||||||
|                         # better error message. |                         # better error message. | ||||||
|                         raise e |                         six.reraise(*exc_info) | ||||||
|             else: |             else: | ||||||
|                 if self.asvar is None: |                 if self.asvar is None: | ||||||
|                     raise e |                     raise | ||||||
|  |  | ||||||
|         if self.asvar: |         if self.asvar: | ||||||
|             context[self.asvar] = url |             context[self.asvar] = url | ||||||
|   | |||||||
| @@ -372,6 +372,22 @@ class Templates(TestCase): | |||||||
|         with self.assertRaises(urlresolvers.NoReverseMatch): |         with self.assertRaises(urlresolvers.NoReverseMatch): | ||||||
|             t.render(c) |             t.render(c) | ||||||
|  |  | ||||||
|  |     @override_settings(TEMPLATE_STRING_IF_INVALID='%s is invalid', SETTINGS_MODULE='also_something') | ||||||
|  |     def test_url_reverse_view_name(self): | ||||||
|  |         # Regression test for #19827 | ||||||
|  |         t = Template('{% url will_not_match %}') | ||||||
|  |         c = Context() | ||||||
|  |         try: | ||||||
|  |             t.render(c) | ||||||
|  |         except urlresolvers.NoReverseMatch: | ||||||
|  |             tb = sys.exc_info()[2] | ||||||
|  |             depth = 0 | ||||||
|  |             while tb.tb_next is not None: | ||||||
|  |                 tb = tb.tb_next | ||||||
|  |                 depth += 1 | ||||||
|  |             self.assertTrue(depth > 5, | ||||||
|  |                 "The traceback context was lost when reraising the traceback. See #19827") | ||||||
|  |  | ||||||
|     def test_url_explicit_exception_for_old_syntax_at_run_time(self): |     def test_url_explicit_exception_for_old_syntax_at_run_time(self): | ||||||
|         # Regression test for #19280 |         # Regression test for #19280 | ||||||
|         t = Template('{% url path.to.view %}')      # not quoted = old syntax |         t = Template('{% url path.to.view %}')      # not quoted = old syntax | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user