[Django] #25370: Error display when makemigrations' field serializing fails with ValueError

80 views
Skip to first unread message

Django

unread,
Sep 8, 2015, 10:09:39 PM9/8/15
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
--------------------------------------+--------------------
Reporter: torstenrudolf | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25370>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 8, 2015, 11:49:51 PM9/8/15
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
--------------------------------------+------------------------------------

Reporter: torstenrudolf | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by charettes):

* 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>

Django

unread,
Sep 9, 2015, 2:54:59 PM9/9/15
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
--------------------------------------+------------------------------------

Reporter: torstenrudolf | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* has_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:2>

Django

unread,
Nov 23, 2015, 8:20:35 PM11/23/15
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
--------------------------------------+------------------------------------
Reporter: torstenrudolf | Owner: awwester
Type: Cleanup/optimization | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by awwester):

* owner: nobody => awwester
* cc: awwester@… (added)
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:3>

Django

unread,
Nov 24, 2015, 6:24:26 PM11/24/15
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
--------------------------------------+------------------------------------
Reporter: torstenrudolf | Owner: awwester
Type: Cleanup/optimization | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by awwester):

working on https://github.com/awwester/django/tree/ticket_25370

--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:4>

Django

unread,
Sep 5, 2020, 7:24:55 AM9/5/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
--------------------------------------+------------------------------------
Reporter: torstenrudolf | Owner: (none)
Type: Cleanup/optimization | Status: new

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by felixxm):

* 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>

Django

unread,
Sep 6, 2020, 5:34:44 PM9/6/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
-------------------------------------+-------------------------------------
Reporter: torstenrudolf | Owner: Tameesh
Type: | Biswas
Cleanup/optimization | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tameesh Biswas):

* owner: (none) => Tameesh Biswas


* status: new => assigned


Comment:

Could I pick this up?

--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:6>

Django

unread,
Sep 7, 2020, 12:30:39 AM9/7/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
-------------------------------------+-------------------------------------
Reporter: torstenrudolf | Owner: Tameesh
Type: | Biswas
Cleanup/optimization | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Of course, there is no need to ask.

--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:7>

Django

unread,
Sep 28, 2020, 9:24:16 PM9/28/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
-------------------------------------+-------------------------------------
Reporter: torstenrudolf | Owner: Tameesh
Type: | Biswas
Cleanup/optimization | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Oct 20, 2020, 2:53:20 AM10/20/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
-------------------------------------+-------------------------------------
Reporter: torstenrudolf | Owner: Tameesh
Type: | Biswas
Cleanup/optimization | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Craig Smith):

[https://github.com/django/django/pull/13570/ PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25370#comment:10>

Django

unread,
Oct 21, 2020, 2:46:30 AM10/21/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
-------------------------------------+-------------------------------------
Reporter: torstenrudolf | Owner: Craig
Type: | Smith

Cleanup/optimization | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* 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>

Django

unread,
Nov 3, 2020, 4:57:01 AM11/3/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
-------------------------------------+-------------------------------------
Reporter: torstenrudolf | Owner: Craig
Type: | Smith
Cleanup/optimization | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "ticket_25370.tar.gz" added.

Sample project.

Django

unread,
Nov 12, 2020, 9:51:48 AM11/12/20
to django-...@googlegroups.com
#25370: Error display when makemigrations' field serializing fails with ValueError
-------------------------------------+-------------------------------------
Reporter: torstenrudolf | Owner: Craig
Type: | Smith
Cleanup/optimization | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* 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>

Reply all
Reply to author
Forward
0 new messages