Opened 3 weeks ago

Closed 2 weeks ago

Last modified 2 weeks ago

#37067 closed Bug (fixed)

Deprecation warnings skip past packages named "django_*"

Reported by: Mike Edmunds Owned by: Fashad Ahmed
Component: Utilities Version: 6.0
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Mike Edmunds)

The django_file_prefixes() utility doesn't include a trailing path separator, so also matches other packages whose installation directories start with "django". As a result, use of deprecated features in those packages will be mis-attributed to some other code outside those packages.

Django's implementation frequently has code like this:

# django.some_module

import warnings
from django.utils.deprecation import RemovedInDjangoXXWarning, django_file_prefixes

def _some_helper():
    ...
    warnings.warn(
        "This is deprecated.",
        RemovedInDjangoXXWarning,
        skip_file_prefixes=django_file_prefixes(),
    )

def some_django_feature():
    ...
    _some_helper()
    ...

The intent is a caller to some_django_feature() outside Django gets a deprecation warning pointed at their own code. (Not pointing at the call to _some_helper() in Django's implementation.)

As currently implemented, django_file_prefixes() returns the directory where Django is installed (in a tuple). E.g., ("/venv/site-packages/django",).

If some_django_feature() is called from a (hypothetical) django_goodies package installed in /venv/site-packages/django_goodies/__init__.py, the warning will skip it too: that filename startswith the django_file_prefixes. The resulting warning will point to the first stack frame outside django_goodies, which may be completely disconnected from the deprecated feature usage.

Change History (16)

comment:1 by Mike Edmunds, 3 weeks ago

Description: modified (diff)

comment:2 by Tim Graham, 3 weeks ago

Triage Stage: UnreviewedAccepted

comment:3 by Mike Edmunds, 3 weeks ago

Easy pickings: set
Owner: Mike Edmunds removed
Status: assignednew

comment:4 by Artyom Kotovskiy, 3 weeks ago

Owner: set to Artyom Kotovskiy
Status: newassigned

comment:5 by Fashad Ahmed, 2 weeks ago

Owner: changed from Artyom Kotovskiy to Fashad Ahmed

Hi Artyom, I’m interested in helping with this ticket. It seems like a straightforward fix in django.utils.deprecation by ensuring django_file_prefixes adds a trailing os.sep to the paths. Are you currently working on a patch, or would you mind if I took a shot at it? Thanks!

Version 0, edited 2 weeks ago by Fashad Ahmed (next)

in reply to:  5 comment:6 by Artyom Kotovskiy, 2 weeks ago

Owner: changed from Fashad Ahmed to Artyom Kotovskiy

Replying to Fashad Ahmed:

Hi Artyom, I’m interested in helping with this ticket. It seems like a straightforward fix in django.utils.deprecation by ensuring django_file_prefixes adds a trailing os.sep to the paths. Would you mind if I took a shot at it? Thanks!

I already fixed it just have to do a pr

comment:7 by Artyom Kotovskiy, 2 weeks ago

Has patch: set

in reply to:  5 ; comment:9 by Jacob Walls, 2 weeks ago

Owner: Artyom Kotovskiy removed
Status: assignednew
Triage Stage: AcceptedReady for checkin

Fashad, although I'm merging your PR in the interest of efficiency, since it took fewer manual edits to polish, next time please respect the existing owner on Trac. It had only been a few hours since it was claimed.

comment:10 by Mike Edmunds, 2 weeks ago

Triage Stage: Ready for checkinAccepted

Just to clarify, the deprecation warnings are still issued even with the bug. They just show a less-helpful stack frame than intended.

[I'm not sure I follow the history references, but they seem to confirm code using skip_file_prefixes had the same problem before the centralized django_file_prefixes() was created.]

comment:11 by Mike Edmunds, 2 weeks ago

Triage Stage: AcceptedReady for checkin

(Sorry, Trac bug changed more than I intended)

in reply to:  10 comment:12 by Jacob Walls, 2 weeks ago

Thanks for the review!

Replying to Mike Edmunds:

[I'm not sure I follow the history references, but they seem to confirm code using skip_file_prefixes had the same problem before the centralized django_file_prefixes() was created.]

Right, all I mean was that it's a "bug" in the "new features" contributed in those commits that they cite the less appropriate stack frames, so we should backport.

comment:13 by Jacob Walls, 2 weeks ago

Owner: set to Fashad Ahmed
Status: newassigned

comment:14 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

Resolution: fixed
Status: assignedclosed

In 60a9c70:

Fixed #37067 -- Added trailing slash in django_file_prefixes().

Ensure skip_file_prefixes does not match sibling packages like django*.

Bug in f42b89f1bf49a5b89ed852b60f79342320a81c5e
and 34bd3ed944bf38792c631b55e581963d44d52284.

comment:15 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

In 8bcd15b:

[6.0.x] Fixed #37067 -- Added trailing slash in django_file_prefixes().

Ensure skip_file_prefixes does not match sibling packages like django*.

Bug in f42b89f1bf49a5b89ed852b60f79342320a81c5e
and 34bd3ed944bf38792c631b55e581963d44d52284.

Backport of 60a9c70496e5d7b971928ce3da5b47c8836a4def from main.

in reply to:  9 comment:16 by Fashad Ahmed, 2 weeks ago

Replying to Jacob Walls:

Fashad, although I'm merging your PR in the interest of efficiency, since it took fewer manual edits to polish, next time please respect the existing owner on Trac. It had only been a few hours since it was claimed.

Thanks for merging and polishing the PR, I appreciate it. Apologies for stepping in while the ticket was already assigned. I’ll make sure to check ownership more carefully before contributing next time. Glad this fix made it in!

Note: See TracTickets for help on using tickets.
Back to Top