Opened 2 years ago

Last modified 22 months ago

#25370 assigned Cleanup/optimization

Error display when makemigrations' field serializing fails with ValueError

Reported by: torstenrudolf Owned by: Adam
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: awwester@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

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:

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

Change History (4)

comment:1 Changed 2 years ago by Simon Charette

Triage Stage: UnreviewedAccepted
Version: 1.8master

Makes sense to me, patch is welcome!

comment:2 Changed 2 years ago by Tim Graham

Has patch: unset

comment:3 Changed 22 months ago by Adam

Cc: awwester@… added
Owner: changed from nobody to Adam
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top