Makemigrations fails when a lambda is used

Issue #29 new
Former user created an issue

Hello,

When an autoslug field is defined with a lambda

AutoSlugField(populate_from=lambda instance: instance.name)

the makemigrations command fails

ValueError: Cannot serialize function: lambda

Comments (1)

  1. Andy repo owner

    Thanks for bug report. As I understand, it's broken since Django 1.7. There's a simple fix: http://stackoverflow.com/questions/27072222/django-1-7-1-makemigrations-fails-when-using-lambda-as-default-for-attribute/27074816#27074816

    I.e. it cannot serialize anonymous functions but it can save refs to module-scoped objects such as named functions. So the fix is to convert the lambda to an ordinary function.

    We need to update django-autoslug documentation to mention that.

  2. Log in to comment