Django 1.7 makemigrations - ValueError: cannot serialize function: lambda

I am switching to Django 1.7. When I try makemigrations for my application, it crashes. Crash Report:

Migrations for 'roadmaps': 0001_initial.py: - Create model DataQualityIssue - Create model MonthlyChange - Create model Product - Create model ProductGroup - Create model RecomendedStack - Create model RecomendedStackMembership - Create model RoadmapMarket - Create model RoadmapUser - Create model RoadmapVendor - Create model SpecialEvent - Create model TimelineEvent - Create model UserStack - Create model UserStackMembership - Add field products to userstack - Add field viewers to userstack - Add field products to recomendedstack - Add field product_group to product - Add field vendor to product - Add field product to dataqualityissue Traceback (most recent call last): File "manage.py", line 29, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py", line 124, in handle self.write_migration_files(changes) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py", line 152, in write_migration_files migration_string = writer.as_string() File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py", line 129, in as_string operation_string, operation_imports = OperationWriter(operation).serialize() File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py", line 80, in serialize arg_string, arg_imports = MigrationWriter.serialize(item) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py", line 245, in serialize item_string, item_imports = cls.serialize(item) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py", line 310, in serialize return cls.serialize_deconstructed(path, args, kwargs) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py", line 221, in serialize_deconstructed arg_string, arg_imports = cls.serialize(arg) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py", line 323, in serialize raise ValueError("Cannot serialize function: lambda") ValueError: Cannot serialize function: lambda 

I found a note that here is https://code.djangoproject.com/ticket/22892

There is also a link to the documentation https://docs.djangoproject.com/en/dev/topics/migrations/#serializing-values

But that does not make me more clear to me. The meassage error did not give me a clue where to look for problems.

Is there a way to determine which line exactly causes the problem?

Any clues?

+6
source share
1 answer

We are having a problem using lambda in a custom field definition.

This is difficult to determine because it is not specified in traceback, and the error does not occur in a particular model that uses such a custom field.

Our way to fix:

  • check all your custom fields (even in third-party libraries).
  • change lambda to a callable that is defined in the module (i.e. not in a user-defined field class)
+9
source

Source: https://habr.com/ru/post/976421/


All Articles