gtaylor / django-athumb

A Django thumbnailer specifically optimized for S3.
http://pypi.python.org/pypi/django-athumb/
BSD 3-Clause "New" or "Revised" License
55 stars 45 forks source link

Problem with django 1.7 migrations #32

Open chrissmejia opened 9 years ago

chrissmejia commented 9 years ago

I get this error when I try to use:

PUBLIC_MEDIA_BUCKET = S3BotoStorage_AllPublic(bucket='public-media')

in my models.

Traceback (most recent call last):
  File "dev_manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 124, in handle
    self.write_migration_files(changes)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 152, in write_migration_files
    migration_string = writer.as_string()
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 131, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 88, in serialize
    arg_string, arg_imports = MigrationWriter.serialize(arg_value)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 333, in serialize
    return cls.serialize_deconstructed(path, args, kwargs)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 239, in serialize_deconstructed
    arg_string, arg_imports = cls.serialize(arg)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 409, in serialize
    "topics/migrations/#migration-serializing" % value
ValueError: Cannot serialize: <athumb.backends.s3boto.S3BotoStorage_AllPublic object at 0x10934d550>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing

Any idea?

gtaylor commented 9 years ago

Hey Chris,

I may suggest trying the storages branch: https://github.com/gtaylor/django-athumb/tree/storages

That included some modernizations, I believe.

chrissmejia commented 9 years ago

Mmm thanks for the help :) but sadly that doesn't work:

pip install git+https://github.com/gtaylor/django-athumb@aa94d968d8743355cda13d466cf21bcc48bf9174

python dev_manage.py makemigrations profile

Migrations for 'profile':
  0002_auto_20150618_0102.py:
    - Alter field image on lawyerprofile
    - Alter field user on lawyerprofile
Traceback (most recent call last):
  File "dev_manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 124, in handle
    self.write_migration_files(changes)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 152, in write_migration_files
    migration_string = writer.as_string()
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 131, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 88, in serialize
    arg_string, arg_imports = MigrationWriter.serialize(arg_value)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 333, in serialize
    return cls.serialize_deconstructed(path, args, kwargs)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 239, in serialize_deconstructed
    arg_string, arg_imports = cls.serialize(arg)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 263, in serialize
    item_string, item_imports = cls.serialize(item)
  File "/Users/christopher/.virtualenvs/wlenv/lib/python2.7/site-packages/django/db/migrations/writer.py", line 409, in serialize
    "topics/migrations/#migration-serializing" % value
ValueError: Cannot serialize: <athumb.validators.ImageUploadExtensionValidator object at 0x1090e3610>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing
gtaylor commented 9 years ago

No idea! I'll accept fixes via pull request, though.

Sorry I couldn't be more help. I'm not actively using athumb at the new gig.

chrissmejia commented 9 years ago

Thanks a lot men, I'm going to think about it, is probably better to switch to some library currently under maintenance.

gtaylor commented 9 years ago

Probably. I remember seeing that sorl is under development again. If that is still the case, it's hard to go wrong there.

chrissmejia commented 9 years ago

Awesome, thanks.

X17 commented 9 years ago

Getting error at

raise ValueError("Cannot serialize: %r\nThere are some values Django cannot serialize into migration files.\nFor more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing" % value)

ValueError: Cannot serialize: athumb.validators.ImageUploadExtensionValidator object at 0x7f031ff4b6d0

There are some values Django cannot serialize into migration files. For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing

It contains lambda, for same i found this : http://stackoverflow.com/questions/27072222/django-1-7-1-makemigrations-fails-when-using-lambda-as-default-for-attribute

jneves commented 8 years ago

I hit this same problem and solved it by adding a deconstruct() method to remove the non-serializable fields to the class ImageWithThumbsField:

def deconstruct(self):
    name, path, args, kwargs = super(ImageWithThumbsField, self).deconstruct()
    if self.validators == [IMAGE_EXTENSION_VALIDATOR] and 'validators' in kwargs:
        del kwargs['validators']
    if 'storage' in kwargs:
        del kwargs['storage']
    return (name, path, args, kwargs)