mirror of
https://github.com/django/django.git
synced 2025-07-19 09:09:13 +00:00
[1.0.X] Fixed #10347 -- Fixed incorrect AttributeError raised when attempting to access a FileField without an instance. Thanks for the report and patch dc.
[9902] from trunk. Also updated svnmerge metadata; all trunk changesets have either been merged or blocked. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9903 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3550aa2d14
commit
c9a63889f6
@ -118,7 +118,7 @@ class FileDescriptor(object):
|
|||||||
|
|
||||||
def __get__(self, instance=None, owner=None):
|
def __get__(self, instance=None, owner=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
raise AttributeError, "%s can only be accessed from %s instances." % (self.field.name(self.owner.__name__))
|
raise AttributeError("The '%s' attribute can only be accessed from %s instances." % (self.field.name, owner.__name__))
|
||||||
file = instance.__dict__[self.field.name]
|
file = instance.__dict__[self.field.name]
|
||||||
if not isinstance(file, FieldFile):
|
if not isinstance(file, FieldFile):
|
||||||
# Create a new instance of FieldFile, based on a given file name
|
# Create a new instance of FieldFile, based on a given file name
|
||||||
|
@ -34,6 +34,12 @@ class Storage(models.Model):
|
|||||||
default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt')
|
default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt')
|
||||||
|
|
||||||
__test__ = {'API_TESTS':"""
|
__test__ = {'API_TESTS':"""
|
||||||
|
# Attempting to access a FileField from the class raises a descriptive error
|
||||||
|
>>> Storage.normal
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
AttributeError: The 'normal' attribute can only be accessed from Storage instances.
|
||||||
|
|
||||||
# An object without a file has limited functionality.
|
# An object without a file has limited functionality.
|
||||||
|
|
||||||
>>> obj1 = Storage()
|
>>> obj1 = Storage()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user