Tuesday, November 2, 2021

Issue with django.forms.fields.FilePathField() and callable path


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:

and documented here:

The commit adding this feature can be found here:

I have an issue when I try to use django.forms.fields.FilePathField()
In the case where path is defined as a callable, and os.scandir(self.path) is called (as showed in  l.1126).
I 'm facing this explicit error:
"scandir: path should be string, bytes, os.PathLike, integer or None, not function"

If I override self.path with a pre-check similar to what it was done for the added feature
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()

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b554a6eb-4978-428f-93b4-324a382557f0n%40googlegroups.com.

No comments:

Post a Comment