#15799 closed Cleanup/optimization (fixed)
Document what exception should be raised when trying to open non-existent file
Reported by: | Jonas H. | Owned by: | Anthony Kugel |
---|---|---|---|
Component: | File uploads/storage | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Collin Anderson | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
What should custom storage backends raise if the file trying to open does not exist? (In Storage._open
) That's not documented anywhere.
Change History (10)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → New feature |
comment:4 by , 18 months ago
Cc: | added |
---|---|
Easy pickings: | set |
Needs documentation: | set |
Type: | New feature → Cleanup/optimization |
FileNotFoundError
was added in Python 3.3 / PEP 3151 and kinda fixed this issue.
Could maybe help to document raising exceptions like FileNotFoundError
here https://docs.djangoproject.com/en/dev/howto/custom-file-storage/ , though probably doesn't need to be super thoroughly documented, as it mostly should be similar to Python's open().
comment:5 by , 16 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 16 months ago
Patch needs improvement: | set |
---|
comment:8 by , 16 months ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
I can't find anywhere in Django that tries to catch an exception from calling .open() on a storage backend, and Django's FileSystemStorage doesn't catch the IOError and re-raise anything else, so at the moment I don't believe there is any such standard to document. For maximum compatibility with FileSystemStorage you'd want to raise IOError, I suppose.
I can see valid use cases (i.e. in reusable apps) for having some common exceptions standardized as part of the Storage interface, so accepting this as a feature request (not necessarily just for documentation, as FileSystemStorage should also use the common exception, and I'm not sure it should be IOError).