Opened 3 years ago

Closed 3 years ago

#33081 closed Bug (invalid)

TypeError: scandir: path should be string, bytes, os.PathLike or None, not function

Reported by: Marco Rizk Owned by: nobody
Component: Forms Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Marco Rizk)

When using a FilePathField as follows

def chunk_path():
    return os.path.join(settings.MEDIA_ROOT, 'footage/chunks')

file = models.FilePathField(path=chunk_path, max_length=200)

I get the error stack of

  File "xxxxxxx/venv/lib/python3.6/site-packages/django/forms/fields.py", line 1126, in __init__
    for f in os.scandir(self.path):
TypeError: scandir: path should be string, bytes, os.PathLike or None, not function

Change History (2)

comment:1 by Marco Rizk, 3 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed

models.FilePathField() accepts a callable path but forms.FilePathField does not (as documented). It looks like an issue in your code not in Django itself.

Note: See TracTickets for help on using tickets.
Back to Top