Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30908 closed Bug (wontfix)

FilePathField raises FileNotFoundError for nonexistent path.

Reported by: Jason Held Owned by: Hasan Ramezani
Component: Forms Version: 2.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The docs around the model of FilePathField show the path as being default None, while the code is empty string.

Also, due to a change in 2.2 around using scandir on the form field for FilePathField, if the path doesn't exist, a FileNotFoundError is issued (same would have happened before the scandir change), but now the try/except logic on OSError (super class) has been removed, in the PR that changed to scandir.

So, the docs are out of date (regardless of whichever value is more sane as a default), and the change on scandir also removed the try/except.

Previously it was not an issue because there was a try/except, so we were caught off guard.

Attachments (1)

test-30908.diff (655 bytes ) - added by Mariusz Felisiak 5 years ago.
Regression test.

Download all attachments as: .zip

Change History (9)

comment:1 by Mariusz Felisiak, 5 years ago

Component: UncategorizedForms
Easy pickings: set
Severity: NormalRelease blocker
Summary: FilePathField doc & field scan dir issueFilePathField raises FileNotFoundError for nonexistent path.
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Thanks for this report, I agree that it's a regression in a0ca4b5694f43c63ea13ba6908eff2bd53ee7ebb. We should restore catching OSError. Documentation issue is not a regression so I sent a separate PR with fix.

Reproduced at fc2b1cc926e34041953738e58fa6ad3053059b22.

by Mariusz Felisiak, 5 years ago

Attachment: test-30908.diff added

Regression test.

comment:2 by GitHub <noreply@…>, 5 years ago

In daa9415f:

Refs #30908 -- Fixed the empty value of forms.FilePathField in docs.

comment:3 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 76964cc:

[3.0.x] Refs #30908 -- Fixed the empty value of forms.FilePathField in docs.

Backport of daa9415f78279855808134e1f40766f6c5f4bdbc from master

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 48df402:

[2.2.x] Refs #30908 -- Fixed the empty value of forms.FilePathField in docs.

Backport of daa9415f78279855808134e1f40766f6c5f4bdbc from master

comment:5 by Hasan Ramezani, 5 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:6 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Severity: Release blockerNormal
Status: assignedclosed

Sorry for the previous acceptance, but it is documented from the very beginning that "This directory must exist" (see 4457ba002d64d4a991b0561c5be69a8c61b2b828). We removed catching OSError in Django 2.2, but it was untested and undocumented behavior.

comment:7 by Hasan Ramezani, 5 years ago

Would it be good to add a test case for OSError?

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 6c6d24a4:

Refs #30908 -- Added test for nonexistent path in forms.FilePathField.

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