Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 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:

Description

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.

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by kkubasik

  • Resolution set to invalid
  • Status changed from new to closed

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 5 years ago by kmtracey

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. admin.site.register(FilePathT)), 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 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.