one up with Pdb:
{{{
(Pdb) l
328 elif isinstance(value, decimal.Decimal):
329 return repr(value), set(["from decimal import
Decimal"])
330 # Django fields
331 elif isinstance(value, models.Field):
332 attr_name, path, args, kwargs = value.deconstruct()
333 -> return cls.serialize_deconstructed(path, args, kwargs)
334 # Classes
335 elif isinstance(value, type):
336 special_cases = [
337 (models.Model, "models.Model", []),
338 ]
(Pdb) a
cls = <class 'django.db.migrations.writer.MigrationWriter'>
value = <django.db.models.fields.related.ForeignKey: site>
{{{
one Up again:
{{{
(Pdb) l
234 for arg in args:
235 arg_string, arg_imports = cls.serialize(arg)
236 strings.append(arg_string)
237 imports.update(arg_imports)
238 for kw, arg in kwargs.items():
239 -> arg_string, arg_imports = cls.serialize(arg)
240 imports.update(arg_imports)
241 strings.append("%s=%s" % (kw, arg_string))
242 return "%s(%s)" % (name, ", ".join(strings)), imports
243
244 @classmethod
(Pdb) a
cls = <class 'django.db.migrations.writer.MigrationWriter'>
path = 'django.db.models.ForeignKey'
args = []
kwargs = {'default': <bound method SiteManager.get_current of
<django.contrib.sites.models.SiteManager object at 0xb647c9ac>>, 'to':
'sites.Site'}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24308>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Ah, seems that this is the trigger for this:
{{{
site = models.ForeignKey(Site,
default=Site.objects.get_current
)
}}}
I change this to:
{{{
site = models.ForeignKey(Site,
default=settings.SITE_ID,
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24308#comment:1>
* status: new => closed
* resolution: => invalid
Comment:
As pointed out in the stacktrace you should refer to the
[https://docs.djangoproject.com/en/dev/topics/migrations/#migration-
serializing documentation].
> Due to the fact !__qualname!__ was only introduced in Python 3, Django
can only serialize the following pattern (an unbound method used within
the class body) on Python 3, and will fail to serialize a reference to it
on Python 2:
> If you are using Python 2, we recommend you move your methods for
upload_to and similar arguments that accept callables (e.g. default) to
live in the main module body, rather than the class body.
--
Ticket URL: <https://code.djangoproject.com/ticket/24308#comment:2>