#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 )
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 , 3 weeks ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 3 weeks ago
| Easy pickings: | set |
|---|---|
| Owner: | removed |
| Status: | assigned → new |
comment:4 by , 3 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
follow-ups: 6 9 comment:5 by , 2 weeks ago
| Owner: | changed from to |
|---|
comment:6 by , 2 weeks ago
| Owner: | changed from to |
|---|
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:8 by , 2 weeks ago
| Severity: | Normal → Release blocker |
|---|
Bug in f42b89f1bf49a5b89ed852b60f79342320a81c5e and 34bd3ed944bf38792c631b55e581963d44d52284 before refactor in 7b26b64a63b5fc15134426a6ee0534dca2a1a855.
follow-up: 16 comment:9 by , 2 weeks ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
| Triage Stage: | Accepted → Ready 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.
follow-up: 12 comment:10 by , 2 weeks ago
| Triage Stage: | Ready for checkin → Accepted |
|---|
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 , 2 weeks ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
(Sorry, Trac bug changed more than I intended)
comment:12 by , 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_prefixeshad the same problem before the centralizeddjango_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 , 2 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:16 by , 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!
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!