#27081: DateField with current date intitialisation pypy migration issue
-------------------------------+--------------------
Reporter: Kurdakov | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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()
but would be better to add types.MethodType check for pypy compatibility
class TestClass(models.Model):
start_date = models.DateField(
verbose_name=u'start date',
default=today,
)
--
Ticket URL: <https://code.djangoproject.com/ticket/27081>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.776a03475c861bdfb0c4421f18da12d0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.