1

I am trying to create a new custom storage class based off S3BotoStorage and I keep getting this error with the following code:

import sys
from django.core.files.storage import Storage
from storages.backends.s3boto import S3BotoStorage


class customStorage(S3BotoStorage):
    def __init__(self, *args, **kwargs):
        kwargs['bucket_name'] = 'bucket_1'
        print >> sys.stderr, 'Creating MyS3Storage'        
        super(S3BotoStorage, self).__init__(*args, **kwargs)

Error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/files/storage.py", line 285, in _setup
self._wrapped = get_storage_class()()
File "/Users/abisson/Sites/poka/common/storages/models.py", line 10, in __init__
super(S3BotoStorage, self).__init__(*args, **kwargs)
TypeError: object.__init__() takes no parameters

I based my answer off Pointing to multiple S3 buckets in s3boto and it should work no? Even normally, we can do:

obj1 = models.FileField(storage=S3BotoStorage(bucket='bucket_1'), upload_to=custom_upload_to)

and it works. (and do pass an argument to the constructor)

Community
  • 1
  • 1
abisson
  • 4,365
  • 9
  • 46
  • 68

1 Answers1

3

You're calling the wrong init function! You mean to call the parent, but you're calling the parent's parent. You need to change your super() line from:

super(S3BotoStorage, self).__init__(*args, **kwargs)

to:

super(customStorage, self).__init__(*args, **kwargs)

In general, the super() command takes the current object and the class of whom's parent you want to call. This is important because there may be times that a person actually does want to call the parent's parent. This is allowed because the child object can still be considered as the parent object when need be.

Paragon
  • 2,692
  • 3
  • 20
  • 27