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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25370>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* version: 1.8 => master
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Makes sense to me, patch is welcome!
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:1>
* has_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:2>
* owner: nobody => awwester
* cc: awwester@… (added)
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:3>
Comment (by awwester):
working on https://github.com/awwester/django/tree/ticket_25370
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:4>
* owner: Adam => (none)
* status: assigned => new
* easy: 0 => 1
Comment:
I think we can deassign after 5 years.
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:5>
* owner: (none) => Tameesh Biswas
* status: new => assigned
Comment:
Could I pick this up?
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:6>
Comment (by felixxm):
Of course, there is no need to ask.
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:7>
Comment (by Ram Parameswaran):
This module (django/db/migrations/serializer.py) was overhauled and merged
in 2016 (see https://github.com/django/django/pull/6059).
Do you think a patch is still required?
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:8>
Comment (by Craig Smith):
[https://github.com/django/django/pull/13570/ PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:10>
* owner: Tameesh Biswas => Craig Smith
* needs_better_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/13582 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:12>
* Attachment "ticket_25370.tar.gz" added.
Sample project.
* status: assigned => closed
* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* resolution: => wontfix
* stage: Accepted => Unreviewed
Comment:
It looks that it's not feasible to get `<app label>.<model name>.<field
name>` or even `<app label>.<model name>` in a reliable way because Django
serializes instances of `field`s from `django.db.models` not a model
attributes. Each approach doesn't work in some cases, e.g. constructing
messages in the `FunctionTypeSerializer` will not work for `lambda`s
defined in the module
{{{
Error during serializing test_one.models.<lambda>: ...
}}}
or for `lambda`s imported from other modules:
{{{
ValueError: Error during serializing test_one.utils.<lambda>: ...
}}}
instead of `ValueError: Error during serializing
test_one.models.Model1.field1`.
--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:13>