﻿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
18478	Field.get_default will stringify everything that isn't a callable	Enrico Zini	nobody	"I'm using a JSON-encoded field that can take any python data structure as default, this way:
{{{
info = fields.ContactInfoField(""Contact info"", blank=True, default={""a"":u""I ♥ Django""})
}}}
and found out that I was getting {{{""{'a': u'I \\u2665 Django'}""}}} as a default value in my model objects.

I tracked it down to Field.get_default, which stringifies all non-callables:
{{{
    def get_default(self):
        """"""
        Returns the default value for this field.
        """"""
        if self.has_default():
            if callable(self.default):
                return self.default()
            return force_unicode(self.default, strings_only=True)
        if (not self.empty_strings_allowed or (self.null and
                   not connection.features.interprets_empty_strings_as_nulls)):
            return None
        return """"
}}}

Indeed this works as expected:
{{{
info = fields.ContactInfoField(""Contact info"", blank=True, default=lambda:{{""a"":u""I ♥ Django""})
}}}

I cannot understand the reason for the different treatment of values and callables, and comments don't help. Field documentation does not mention this behaviour either. From what little I can understand, this looks like a bug, "	Cleanup/optimization	closed	Documentation	1.4	Normal	fixed		timograham@…	Accepted	1	0	0	0	0	0
