From 34bd3ed944bf38792c631b55e581963d44d52284 Mon Sep 17 00:00:00 2001 From: farhan Date: Thu, 4 Sep 2025 17:05:03 +0500 Subject: [PATCH] Refs #36559, #35667 -- Used skip_file_prefixes in PartialTemplate.source warning. --- django/template/base.py | 4 +++- tests/template_tests/test_partials.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/django/template/base.py b/django/template/base.py index 37e7243d5c..b87291746b 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -52,10 +52,12 @@ times with multiple contexts) import inspect import logging +import os import re import warnings from enum import Enum +import django from django.template.context import BaseContext from django.utils.formats import localize from django.utils.html import conditional_escape @@ -327,7 +329,7 @@ class PartialTemplate: "PartialTemplate.source is only available when template " "debugging is enabled.", RuntimeWarning, - stacklevel=2, + skip_file_prefixes=(os.path.dirname(django.__file__),), ) return self.find_partial_source(template.source) diff --git a/tests/template_tests/test_partials.py b/tests/template_tests/test_partials.py index 9762436fdc..984f0441c2 100644 --- a/tests/template_tests/test_partials.py +++ b/tests/template_tests/test_partials.py @@ -144,8 +144,9 @@ class PartialTagsTests(TestCase): RuntimeWarning, "PartialTemplate.source is only available when template " "debugging is enabled.", - ): + ) as ctx: self.assertEqual(partial.template.source, "") + self.assertEqual(ctx.filename, __file__) class RobustPartialHandlingTests(TestCase):