Skip to content

Commit 8f5d2c3

Browse files
charettesnessita
authored andcommitted
[5.1.x] Refs #35326 -- Adjusted deprecation warning stacklevel in FileSystemStorage.OS_OPEN_FLAGS.
Backport of 47f18a7 from main.
1 parent c87007a commit 8f5d2c3

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

django/core/files/storage/filesystem.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(
4848
"Overriding OS_OPEN_FLAGS is deprecated. Use "
4949
"the allow_overwrite parameter instead.",
5050
RemovedInDjango60Warning,
51+
stacklevel=2,
5152
)
5253

5354
@cached_property

docs/releases/5.1.1.txt

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ Bugfixes
2323
* Adjusted the deprecation warning ``stacklevel`` in :meth:`.Model.save` and
2424
:meth:`.Model.asave` to correctly point to the offending call site
2525
(:ticket:`35060`).
26+
27+
* Adjusted the deprecation warning ``stacklevel`` when using ``OS_OPEN_FLAGS``
28+
in :class:`~django.core.files.storage.FileSystemStorage` to correctly point
29+
to the offending call site (:ticket:`35326`).

tests/file_storage/tests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,11 @@ def setUp(self):
635635
def test_os_open_flags_deprecation_warning(self):
636636
msg = "Overriding OS_OPEN_FLAGS is deprecated. Use the allow_overwrite "
637637
msg += "parameter instead."
638-
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
638+
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
639639
self.storage = self.storage_class(
640640
location=self.temp_dir, base_url="/test_media_url/"
641641
)
642+
self.assertEqual(ctx.filename, __file__)
642643

643644

644645
# RemovedInDjango60Warning: Remove this test class.

0 commit comments

Comments
 (0)