Opened 14 years ago

Closed 16 months ago

Last modified 16 months ago

#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 Carl Meyer, 14 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

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).

comment:2 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:3 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:4 by Collin Anderson, 18 months ago

Cc: Collin Anderson added
Easy pickings: set
Needs documentation: set
Type: New featureCleanup/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 Anthony Kugel, 16 months ago

Owner: changed from nobody to Anthony Kugel
Status: newassigned

comment:6 by Mariusz Felisiak, 16 months ago

Has patch: set
Needs documentation: unset

comment:7 by Mariusz Felisiak, 16 months ago

Patch needs improvement: set

comment:8 by Mariusz Felisiak, 16 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 16 months ago

Resolution: fixed
Status: assignedclosed

In 8edaf07a:

Fixed #15799 -- Doc'd that Storage._open() should raise FileNotFoundError when file doesn't exist.

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 16 months ago

In a22aeef5:

[4.2.x] Fixed #15799 -- Doc'd that Storage._open() should raise FileNotFoundError when file doesn't exist.

Backport of 8edaf07a28a3e3848ab1edbdcd2fdc25e6bd6015 from main

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