﻿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
27081	Allow migrations to serialize methods on pypy	Sergey Kurdakov	nobody	"if model contains DateField and it is initialized with current date

example:

from datetime import date
{{{
#!python
class TestClass(models.Model):

    start_date = models.DateField(
        verbose_name=u'start date',
        default=date.today,
        )
}}}
pypy migrations will fail

django/db/migrations/writer.py"", line 540, in serialize   ""topics/migrations/#migration-serializing"" % (value, get_docs_version())
ValueError: Cannot serialize: <bound method type.today of <class 'datetime.date'>>

reason:
code for serialising methods in Django checks 
`if isinstance(value, (types.FunctionType, types.BuiltinFunctionType))`
which succeeds on cpython because datetime.date.today is a
BuiltinFunctionType, wheras it's a types.MethodType on pypy and this check is missing in django
( link https://github.com/django/django/blob/3b383085fb89a48e756383e7cd5d3bd867353ba1/django/db/migrations/serializer.py#L379 )

a solution for client code is to declare local function
{{{
#!python

def today():
    return date.today()


class TestClass(models.Model):

    start_date = models.DateField(
        verbose_name=u'start date',
        default=today,
        )
}}}

but would be better to add types.MethodType check for pypy compatibility"	Bug	closed	Migrations	1.9	Normal	fixed			Accepted	1	0	0	0	0	0
