[Django] #33254: Issue with django.forms.fields.FilePathField() and callable path

21 views
Skip to first unread message

Django

unread,
Nov 2, 2021, 12:26:30 PM11/2/21
to django-...@googlegroups.com
#33254: Issue with django.forms.fields.FilePathField() and callable path
-----------------------------------------+-------------------------------
Reporter: Chakib | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 3.2
Severity: Normal | Keywords: FilePathField
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-------------------------------
Hi,

First post here, so I don't know if it's the correct channel for this kind
of issue.
Sorry if it's not.

Since v 3.0 we can set path attribute as a callable in a
models.fields.FilePathField(),
as discussed here:
[https://code.djangoproject.com/ticket/29529]

and documented here:
[https://docs.djangoproject.com/en/3.0/ref/models/fields/#django.db.models.FilePathField.path]

The commit adding this feature can be found here:
[https://github.com/django/django/commit/ef082ebb84f00e38af4e8880d04e8365c2766d34]

I have an issue when I try to use django.forms.fields.FilePathField()
[https://github.com/django/django/blob/stable/3.2.x/django/forms/fields.py#L1095]

In the case where path is defined as a callable, and
"os.scandir(self.path)" is called (as showed in
[https://github.com/django/django/blob/stable/3.2.x/django/forms/fields.py#L1126]).
I have this explicit error:
"scandir: path should be string, bytes, os.PathLike, integer or None, not
function"

If I monkey-patch "self.path" in the {{{__init__}}} method with a pre-
check similar to what it was done for the added feature
[https://github.com/django/django/blob/stable/3.2.x/django/db/models/fields/__init__.py#L1711]
it seems to solve this issue.
{{{
...
path = self.path() if callable(self.path) else self.path
for f in os.scandir(path):
...
}}}

I don't know if it's a bug or if I miss something using
models.fields.FilePathField() and django.forms.fields.FilePathField()

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

Django

unread,
Nov 2, 2021, 12:36:01 PM11/2/21
to django-...@googlegroups.com
#33254: Issue with django.forms.fields.FilePathField() and callable path
-------------------------------+--------------------------------------
Reporter: Chakib | Owner: nobody
Type: Uncategorized | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: FilePathField | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

`models.FilePathField` accepts a callable `path`, but
`forms.FilePathField` doesn't.

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

Django

unread,
Nov 2, 2021, 12:36:47 PM11/2/21
to django-...@googlegroups.com
#33254: Issue with django.forms.fields.FilePathField() and callable path
-------------------------------+--------------------------------------
Reporter: Chakib | Owner: nobody
Type: Uncategorized | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: FilePathField | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Closing per TicketClosingReasons/UseSupportChannels.

--
Ticket URL: <https://code.djangoproject.com/ticket/33254#comment:2>

Reply all
Reply to author
Forward
0 new messages