Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#34155 closed Uncategorized (needsinfo)

ModelAdmin.render_change_form does not lowercase the app_label when setting template directories

Reported by: Rishi Diwan Owned by: nobody
Component: contrib.admin Version: 3.2
Severity: Normal Keywords:
Cc: Carlton Gibson Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Rishi Diwan)

In case of differing environments, such as the linux FS and the OSX FS, folders case-matching is important.

Consider an application with:
app label = "App"
model name = "Inventory" with tablename="inventory"

If a particular model's change_form.html needs to be overwritten we would do the following
Overwrite template/django/admin/App/inventory/change_form.html
This works fine on Linux systems.
However on OSX systems the file shows up as template/django/admin/app/inventory/change_form.html.
This breaks the functionality since the template is no longer found in the App/inventory directory.

The app_label variable should be lowercased so the differing file systems do not cause this issue.

Change History (8)

comment:1 by Rishi Diwan, 2 years ago

Version: 4.13.2

comment:2 by Rishi Diwan, 2 years ago

Description: modified (diff)

comment:3 by Rishi Diwan, 2 years ago

Easy pickings: set

comment:4 by Rishi Diwan, 2 years ago

Component: Uncategorizedcontrib.admin

in reply to:  description comment:5 by Mariusz Felisiak, 2 years ago

Cc: Carlton Gibson added
Easy pickings: unset
Resolution: needsinfo
Status: newclosed

The app_label variable should be lowercased so the differing file systems do not cause this issue.

app and App are two different directories, so forcing lowercase would be highly backward incompatible. As far as I'm aware, the APFS filesystem is not case insensitive so I'm sure what kind of issue you are facing 🤔

comment:6 by Carlton Gibson, 2 years ago

macOS APFS is case insensitive:

% mkdir App
% mkdir app
mkdir: app: File exists
% ls
App
% diskutil info /System/Volumes/Data | grep Personality
   File System Personality:   APFS

However...

However on OSX systems the file shows up as template/django/admin/app/inventory/change_form.html.
This breaks the functionality since the template is no longer found in the App/inventory directory.

On macOS I'd expect the template to be found regardless of the casing of the app directory.
(A full runnable example showing otherwise please.)

This is a long-standing gotcha of macOS. Linux has case sensitive names so don't use App unless you mean it there. It's best just to use lowercase, and then you don't hit problems.
(Use AppConfig.verbose_name if you want that for display purposes.)

...forcing lowercase would be highly backward incompatible

Exactly. This isn't something we can realistically change.

in reply to:  6 comment:7 by Mariusz Felisiak, 2 years ago

macOS APFS is case insensitive:

TIL

comment:8 by Rishi Diwan, 2 years ago

I agree backward compatibility breaks, but there is a consistency issue here.
InculsionAdminNode.render explicitly does a app_label.lower() so we now have two folders with different cases for the different admin templates.
The case-sensitive folder has issues in the OSX folders because of the FS.

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