Opened 2 years ago

Closed 2 years ago

#33880 closed Cleanup/optimization (invalid)

Ambigous error message in FilePathFields.

Reported by: Willem Van Onsem Owned by: nobody
Component: Database layer (models, ORM) Version: 4.0
Severity: Normal Keywords:
Cc: Carlton Gibson Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Django's FilePathField (https://docs.djangoproject.com/en/dev/ref/models/fields/#filepathfield) specifies for the allow_files and allow_folders:

Optional. Either True or False. Default is True. Specifies whether files in the specified location should be included. Either this or allow_folders must be True.

(analogue for allow_folders)

This seems to hint that one should set allow_files to True or allow_folders to True; but not both at the same time.

In the corresponding code, it seems to say:

    def _check_allowing_files_or_folders(self, **kwargs):
        if not self.allow_files and not self.allow_folders:
            return [
                checks.Error(
                    "FilePathFields must have either 'allow_files' or 'allow_folders' "
                    "set to True.",
                    obj=self,
                    id="fields.E140",
                )
            ]
        return []

The code block thus checks that both parameters are not false (at the same time).

It might be better to say "allow_files or allow_folders should be set to True", since the either might hint that this is an exclusive or (based on this post https://english.stackexchange.com/questions/13889/does-either-a-or-b-preclude-both-a-and-b ).

This should then be both updated for the documentation, and for the error codes I think.

Change History (2)

comment:1 by Isaac Barrezueta, 2 years ago

Hi Willem. The way I understand it is that at least one of the attributes has to be True.
I haven't run the code myself, but it also seems like a user would only run into this Error if they set both allow_files and allow_folders to false. In that scenario, the wording doesn't seem like too much a problem.

comment:2 by Mariusz Felisiak, 2 years ago

Cc: Carlton Gibson added
Resolution: invalid
Status: newclosed
Summary: Ambigous error message regarding "FilePathFields must have either 'allow_files' or 'allow_folders' set to True."Ambigous error message in FilePathFields.
Type: UncategorizedCleanup/optimization

IMO, the current wording is correct. either means (according to the Oxford English Dictionary):

  • one or the other of two; it does not matter which
  • each of two.
Note: See TracTickets for help on using tickets.
Back to Top