Opened 8 years ago
Closed 8 years ago
#27081 closed Bug (fixed)
Allow migrations to serialize methods on pypy
Reported by: | Sergey Kurdakov | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
if model contains DateField and it is initialized with current date
example:
from datetime import date
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
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
Change History (3)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Component: | Uncategorized → Migrations |
---|---|
Has patch: | set |
Summary: | DateField with current date intitialisation pypy migration issue → Allow migrations to serialize methods on pypy |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
Seems okay. That proposed change fixes these existing test failures on pypy, so I guess no new tests are needed:
PR