diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-19 12:40:46 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-19 12:40:46 +0000 |
| commit | ebfe9383bfbc53cb6c29e1170d99f64feb9ad010 (patch) | |
| tree | faf395369df77a95af3bdf02ddf9d8426a75dadf /django/utils | |
| parent | 56eb340528d392612f3229b4bd8b7416553c3b15 (diff) | |
Fixed #13370 -- Corrected the handling of pickling for lazy() proxy objects. Thanks to Alex Gaynor for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13000 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/functional.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py index b66fdd3012..4b070f0ed4 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -147,11 +147,6 @@ def lazy(func, *resultclasses): the lazy evaluation code is triggered. Results are not memoized; the function is evaluated on every access. """ - # When lazy() is called by the __reduce_ex__ machinery to reconstitute the - # __proxy__ class it can't call with *args, so the first item will just be - # a tuple. - if len(resultclasses) == 1 and isinstance(resultclasses[0], tuple): - resultclasses = resultclasses[0] class __proxy__(Promise): """ @@ -168,8 +163,11 @@ def lazy(func, *resultclasses): if self.__dispatch is None: self.__prepare_class__() - def __reduce_ex__(self, protocol): - return (lazy, (self.__func, resultclasses), self.__dict__) + def __reduce__(self): + return ( + _lazy_proxy_unpickle, + (self.__func, self.__args, self.__kw) + resultclasses + ) def __prepare_class__(cls): cls.__dispatch = {} @@ -249,6 +247,9 @@ def lazy(func, *resultclasses): return wraps(func)(__wrapper__) +def _lazy_proxy_unpickle(func, args, kwargs, *resultclasses): + return lazy(func, *resultclasses)(*args, **kwargs) + def allow_lazy(func, *resultclasses): """ A decorator that allows a function to be called with one or more lazy |
