Skip to content

Commit 34bd3ed

Browse files
FarhanAliRazajacobtylerwalls
authored andcommitted
Refs #36559, #35667 -- Used skip_file_prefixes in PartialTemplate.source warning.
1 parent 686a8a6 commit 34bd3ed

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

django/template/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@
5252

5353
import inspect
5454
import logging
55+
import os
5556
import re
5657
import warnings
5758
from enum import Enum
5859

60+
import django
5961
from django.template.context import BaseContext
6062
from django.utils.formats import localize
6163
from django.utils.html import conditional_escape
@@ -327,7 +329,7 @@ def source(self):
327329
"PartialTemplate.source is only available when template "
328330
"debugging is enabled.",
329331
RuntimeWarning,
330-
stacklevel=2,
332+
skip_file_prefixes=(os.path.dirname(django.__file__),),
331333
)
332334
return self.find_partial_source(template.source)
333335

tests/template_tests/test_partials.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ def test_template_source_warning(self):
144144
RuntimeWarning,
145145
"PartialTemplate.source is only available when template "
146146
"debugging is enabled.",
147-
):
147+
) as ctx:
148148
self.assertEqual(partial.template.source, "")
149+
self.assertEqual(ctx.filename, __file__)
149150

150151

151152
class RobustPartialHandlingTests(TestCase):

0 commit comments

Comments
 (0)