FilePathField - Django 3.x allowed "path" as callable #8234
Unanswered
chakibBH
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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 the "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:
django/django@ef082eb
DRF documentation stating this field corresponds to django.forms.fields.FilePathField()
(https://www.django-rest-framework.org/api-guide/fields/#filepathfield)
Also we can see how the Django's form field is used by DRF's serializer field:
https://github.com/encode/django-rest-framework/blob/master/rest_framework/fields.py#L1504
I have an issue in the case where path is defined as a callable in my model field,
when 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 'm facing this explicit error:
"scandir: path should be string, bytes, os.PathLike, integer or None, not function"
I tried to reach the djangoproject team and opened a ticket:
https://code.djangoproject.com/ticket/33254
To see if this behaviour is intendeded.
So my questionis: Should "path" attribute be checked before send to django.forms.fields.FilePathField() to avoid the scandir error ?
Something similar to what they have done whene they allowed "path" to be a callabel:
Beta Was this translation helpful? Give feedback.
All reactions