Opened 14 years ago

Last modified 8 years ago

#13327 new

FileField/ImageField accessor methods throw unnecessary exceptions when they are blank or null. — at Version 1

Reported by: kevin.howerton@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex Gaynor)

Many of the accessor methods on the FileField call this method:

    def _require_file(self):
        if not self:
            raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)

This method defeats the blank or null features, and has 0 benefit.

The preferred behavior should be that it raises an error if the field is set, but the file does not exist. However if you try to retrieve a URL or path from a file-field it should return None if the field is Null or if the field is blank. Not sure what the reasoning behind throwing an error here, is but it seems extremely dis-advantageous in practice requiring every image or file-field that can be blank/null to have if/else statement wrapped around it in templates to prevent 500 errors.

Change History (1)

comment:1 by Alex Gaynor, 14 years ago

Description: modified (diff)

Please use preview.

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