Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#36961 closed Bug (fixed)

django_file_prefixes() raises TypeError if Django is imported by namespace

Reported by: Jacob Walls Owned by: Jacob Walls
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: no UI/UX: no

Description

cd one level above your django checkout, and launch a python shell.

Calling django_file_prefixes will fail:

>>> import django
>>> django.__file__ is None
True
>>> from django.utils.deprecation import django_file_prefixes
>>> django_file_prefixes()
Traceback (most recent call last):
  File "<python-input-1>", line 5, in <module>
    django_file_prefixes()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/jwalls/django/django/utils/deprecation.py", line 18, in django_file_prefixes
    return (os.path.dirname(file),)
            ~~~~~~~~~~~~~~~^^^^^^
  File "<frozen posixpath>", line 178, in dirname
TypeError: expected str, bytes or os.PathLike object, not NoneType

How I found this was by testing deprecation warnings, so what I'm concluding is that deprecation warnings might crash in 6.0 if you import Django by namespace.

Change History (7)

comment:1 by Jacob Walls, 3 weeks ago

Summary: django_file_prefixes() raises AttributeError if Django is imported by namespacedjango_file_prefixes() raises TypeError if Django is imported by namespace

comment:2 by Jacob Walls, 3 weeks ago

comment:3 by Natalia Bidart, 3 weeks ago

Triage Stage: UnreviewedAccepted

Thank you Jacob! I find "cd one level above your django checkout, and launch a python shell" a bit of a niche use case but the fix is quite straightforward, so accepting.

comment:4 by Jacob Walls, 3 weeks ago

Yeah, I only expect this to happen "accidentally" in CI/CD pipelines when cwd is not managed cleanly, similar to the issues we see crop up when django's runtests.py is sometimes run from /tests versus /.

comment:5 by Natalia Bidart, 3 weeks ago

Triage Stage: AcceptedReady for checkin

comment:6 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

Resolution: fixed
Status: assignedclosed

In c1d8646:

Fixed #36961 -- Fixed TypeError in deprecation warnings if Django is imported by namespace.

comment:7 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

In 1b22d53:

[6.0.x] Fixed #36961 -- Fixed TypeError in deprecation warnings if Django is imported by namespace.

Backport of c1d8646ec219b8b90ebdd463f40e5767876658a0 from main.

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