﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25370	Error display when makemigrations' field serializing fails with ValueError	torstenrudolf	Craig Smith	"In django1.8.4 the error message displayed, when the field serialization fails (e.g. because there is a lambda function used for one argument) is not very helpful.

It would be nice to know on which field the error happened.

a simple patch could be inside django.db.migrations.writer to wrap line 377 (seems to be 422 in current master https://github.com/django/django/blob/e34226fc37dfa9eba89d913fd7ab8e95663b0d64/django/db/migrations/writer.py#L422) 
{{{#!python
elif isinstance(value, models.Field):
    attr_name, path, args, kwargs = value.deconstruct()
    return cls.serialize_deconstructed(path, args, kwargs)
}}}
into a try-except block like this:

{{{#!python
elif isinstance(value, models.Field):
    attr_name, path, args, kwargs = value.deconstruct()
    try:
        return cls.serialize_deconstructed(path, args, kwargs)
    except ValueError as e:
        e.args = ('During serialization of the field {} the following blew up: {}'.format(value, e.args[0]), ) + e.args[1:]
        raise e, None, sys.exc_info()[2]
}}}

end of the traceback before the change:
{{{
...
.../local/lib/python2.7/site-packages/django/db/migrations/writer.py"", line 415, in serialize
    raise ValueError(""Cannot serialize function: lambda"")
ValueError: Cannot serialize function: lambda
}}}

after the change:
{{{
...
.../local/lib/python2.7/site-packages/django/db/migrations/writer.py"", line 419, in serialize
    raise ValueError(""Cannot serialize function: lambda"")
ValueError: During serialization of the field <app_label>.<model_name>.<field_name> the following blew up: Cannot serialize function: lambda
}}}"	Cleanup/optimization	closed	Migrations	dev	Normal	wontfix		awwester@…	Unreviewed	0	0	0	0	1	0
