﻿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
25389	SimpleLazyObject doesn't pickle correctly when wrapping a Model	Ben Kraft	Ben Kraft	"Given a `SimpleLazyObject` wrapping an instance of a Django model, if the `SimpleLazyObject` has not yet been initialized, pickling it will not correctly save the `_django_version` attribute added by [https://github.com/django/django/commit/42736ac8e8c31137131714013951249a09e6e7d4 42736ac8].  This happens because `SimpleLazyObject`'s overridden `__reduce_ex__` clobbers that of Model, and means that unpickling the pickled object will raise a warning.  An example is given [https://gist.github.com/benjaminjkraft/2d330e22a58681c5db5c#file-raises_warning-py here].  This is especially relevant given that `request.user` is a `SimpleLazyObject` wrapping a model instance, so this will happen when pickling an untouched `request.user`.

Furthermore, pickling a `SimpleLazyObject` wrapping a class which does certain scary things to its `__dict__` and overrides `__reduce__` can cause an error while pickling.  An abstract example is given [https://gist.github.com/benjaminjkraft/2d330e22a58681c5db5c#file-raises_error-py here].  (I don't think that supporting this case is a necessity, but it was how I noticed the above issue, and the attached patch fixes both cases.)

Currently the behavior is effectively to just initialize and then pickle the wrapped object.  I have and will attach a patch which does that in a more direct way that works in both of the above cases.  It also adds a regression test which covers both of the above cases."	Bug	closed	Database layer (models, ORM)	1.8	Release blocker	fixed			Ready for checkin	1	0	0	0	0	0
