Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10056 closed (invalid)

Problem with non-ASCII characters in FilePathField in contrib.admin

Reported by: andrew.mcmurry@… Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I have a model including a FilePathField. The directory in question contains filenames with non-ASCII characters (on Linux). I have been trying to add entries for this model using the admin pages. I get a pull-down menu listing all available files, with the non-ASCII characters displayed correctly. I choose a filename containing non-ASCII characters, and the field value displays correctly. I try to submit the new object and it fails, with 'Select Valid Choice - xxxxx is not one of the available choices'. Filenames containing no non-ASCII characters work fine.

Change History (4)

comment:1 Changed 8 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Kevin Kubasik

Resolution: invalid
Status: newclosed

We don't want to be limiting the possible files to select, if you want, FilePathField takes a regex to determine which files should be displayed, so you could hide the non-ascii files. Or, if you want to allow them, you could subclass the Form's clean() method and change the validation rules. Overall, the opinion appears to be that we can't allow filenames that filesystems don't support, and we don't want to limit which files you see in the dropdown (by default).

I'm going to close this, but feel free to reopen if I'm super-wrong or totally off-base.

comment:3 Changed 8 years ago by Karen Tracey

The original problem description makes it sound like by default a FilePathField will list in the select box files that, if selected, will lead to a "not a valid selection -- please select a valid choice" form validation error. If that were so, this would not (imo) be an invalid ticket. If a file is listed in the select box, it should be accepted as a valid choice, without requiring override of the FilePathField regex or the form field's clean method. However, I cannot recreate the problem as described so I think there is some piece of the puzzle missing from the original problem description. Using this model:

class FilePathT(models.Model):
    fpath = models.FilePathField(path='/home/kmt/tmp')

    def __unicode__(self):
        return self.fpath

registered with no special customization in the admin (i.e., I cannot recreate any problem where the drop-down list includes a file to choose that is then rejected on selection as "not a valid choice". I can select files with Chinese (or maybe they're Japanese) characters and save them just fine.

comment:4 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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