Opened 13 years ago
Closed 9 years ago
#17917 closed Bug (fixed)
Pickling queryset with annotations on related fields with callable defaults fails
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | queryset, pickle, aggregation |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given the following models:
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
"TypeError: expected string or Unicode object, NoneType found":
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:
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.
Change History (6)
comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 12 years ago
comment:3 by , 12 years ago
Component: | ORM aggregation → Database layer (models, ORM) |
---|
comment:4 by , 9 years ago
Has patch: | set |
---|
Fixed by f403653cf146384946e5c879ad2a351768ebc226 in Django 1.6.
PR to add a unit test. Annotating across a relation isn't required to trigger the exception.
comment:6 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Indeed, I could reproduce the problem. Pickling works without the annotation and crashes with the annotation.