[Django] #33880: Ambigous error message regarding "FilePathFields must have either 'allow_files' or 'allow_folders' set to True."

5 views
Skip to first unread message

Django

unread,
Jul 31, 2022, 1:04:54 PM7/31/22
to django-...@googlegroups.com
#33880: Ambigous error message regarding "FilePathFields must have either
'allow_files' or 'allow_folders' set to True."
-------------------------------------+-------------------------------------
Reporter: Willem | Owner: nobody
Van Onsem |
Type: | Status: new
Uncategorized |
Component: Database | Version: 4.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33880>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 31, 2022, 3:56:07 PM7/31/22
to django-...@googlegroups.com
#33880: Ambigous error message regarding "FilePathFields must have either
'allow_files' or 'allow_folders' set to True."
-------------------------------------+-------------------------------------
Reporter: Willem Van Onsem | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by barrezuetai):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33880#comment:1>

Reply all
Reply to author
Forward
0 new messages