#21102 closed Bug (fixed)
Cannot pickle/unpickle a QuerySet that prefetches related objects more than once (Pickling Idempotency)
Reported by: | Minjong Chung | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.5 |
Severity: | Release blocker | Keywords: | ORM, pickle, cache |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
https://code.djangoproject.com/ticket/20157
https://code.djangoproject.com/ticket/20257
https://github.com/django/django/commit/bac187c0d8e829fb3ca2ca82965eabbcbcb6ddd5#django/db/models/query.py
The patch above introduced a new bug for pickling idempotency. Simply put, a QuerySet that prefetches related objects cannot be pickled and unpickled more than once. The second pickling attempt raises an exception.
With the follow models:
class Post(models.Model): post_date = models.DateTimeField(default=datetime.datetime.now) class Material(models.Model): post = models.ForeignKey(Post, related_name='materials')
This code won't run smoothly:
post = Post.objects.create() posts = Post.objects.all() posts = posts.prefetch_related('materials') posts = pickle.loads(pickle.dumps(posts)) posts = pickle.loads(pickle.dumps(posts))
Change History (5)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
bmispelon confirmed this affects 1.5.x only.
comment:3 by , 11 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
A new pull request was submitted.
https://github.com/django/django/pull/1627