﻿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
17917	Pickling queryset with annotations on related fields with callable defaults fails	jensadne@…	nobody	"Given the following models:

{{{
#!python
class Person(models.Model):
    name = models.CharField(max_length=32)

class LogEntry(models.Model):
    person = models.ForeignKey(Person, related_name='log_entries')
    created = models.DateTimeField(default=datetime.now)
}}}


the following function fails with
{{{
#!python
""TypeError: expected string or Unicode object, NoneType found"":
}}}

{{{
#!python
def pickle_persons_with_latest_logentry_time():
    qs = Person.objects.all().annotate(latest_logentry_time=Max('log_entries__created'))
    pickled = cPickle.dumps(qs)
}}}

Changing to using the pickle module instead of cPickle changes the exception to:
{{{
#!python
PicklingError: Can't pickle <built-in method now of type object at 0x7f3e064bb020>: it's not found as __main__.now
}}}
so this looks related to #13328

Tested with Django 1.3.1 on python 2.4.3 (Centos 5), Django 1.3.1 on python 2.7 (Fedora 14), and latest Django-SVN with python 2.7, and got the same result on all of them."	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	queryset,pickle,aggregation		Accepted	1	0	0	0	0	0
