16

I am trying to upgrade a django app from django 1.6.6 to 1.7 and am using python 2.7.8. When I run python manage.py makemigrations, I get the following error:

ValueError: Cannot serialize: <storages.backends.s3boto.S3BotoStorage object at 0x11116eed0>
There are some values Django cannot serialize into migration files.

And here is the relevant code:

protected_storage = storages.backends.s3boto.S3BotoStorage(
      acl='private',
      querystring_auth=True,
      querystring_expire=3600,
    )


    class Document(models.Model):
        ...
        file = models.FileField(upload_to='media/docs/', max_length=10000, storage=protected_storage)

        def __unicode__(self):
            return "%s" % self.candidate

        def get_absolute_url(self):
            return reverse('documents', args=[str(self.pk)])

I've read the migration docs and read about a similar issue here, but I've been unable to resolve this. My app uses django-storages and boto to save files onto Amazon S3. Any help is appreciated.

mcastle
  • 2,882
  • 3
  • 25
  • 43

2 Answers2

29

Just make a deconstructible subclass and use it instead.

from django.utils.deconstruct import deconstructible


@deconstructible
class MyS3BotoStorage(S3BotoStorage):
    pass
mcastle
  • 2,882
  • 3
  • 25
  • 43
Dominique PERETTI
  • 1,063
  • 12
  • 12
7

The basic issue here is that you are trying to use Django 1.7 with a package (django-storages) that doesn't appear to have been updated to work with that version yet.

Here are some excerpts from the documentation to explain what is happening:

Migrations are just Python files containing the old definitions of your models - thus, to write them, Django must take the current state of your models and serialize them out into a file.

While Django can serialize most things, there are some things that we just can’t serialize out into a valid Python representation - there’s no Python standard for how a value can be turned back into code.

You can let Django serialize your own custom class instances by giving the class a deconstruct() method.

So the solution here is to give the class storages.backends.s3boto.S3BotoStorage a deconstruct() method. That will probably be as easy as applying the @deconstructible class decorator.

Presumably the package will incorporate this change at some point (or perhaps the master branch already has it?), but you could also just patch it yourself.

Community
  • 1
  • 1
Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
  • ```@deconstructible class MyS3BotoStorage(S3BotoStorage): pass``` – Dominique PERETTI Oct 24 '14 at 10:32
  • The comment about django-storages fixed it for me. I upgraded and that took care of things. In my circumstance, using @deconstructible did not. – Guerry Feb 29 '16 at 23:10
  • For custom **deconstruct()** method -- see http://stackoverflow.com/questions/31953802/upgrading-from-django-1-6-to-1-7-getting-callable-is-not-serialize-when-running – storm_m2138 Oct 11 '16 at 21:46