Author: russellm
Date: 2010-04-19 07:40:46 -0500 (Mon, 19 Apr 2010)
New Revision: 13000

Modified:
   django/trunk/django/utils/functional.py
   django/trunk/tests/regressiontests/i18n/tests.py
Log:
Fixed #13370 -- Corrected the handling of pickling for lazy() proxy objects. 
Thanks to Alex Gaynor for the report and patch.

Modified: django/trunk/django/utils/functional.py
===================================================================
--- django/trunk/django/utils/functional.py     2010-04-19 11:57:04 UTC (rev 
12999)
+++ django/trunk/django/utils/functional.py     2010-04-19 12:40:46 UTC (rev 
13000)
@@ -147,11 +147,6 @@
     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 @@
             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 @@
 
     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

Modified: django/trunk/tests/regressiontests/i18n/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/tests.py    2010-04-19 11:57:04 UTC 
(rev 12999)
+++ django/trunk/tests/regressiontests/i18n/tests.py    2010-04-19 12:40:46 UTC 
(rev 13000)
@@ -1,8 +1,9 @@
 # -*- encoding: utf-8 -*-
+import datetime
+import decimal
 import os
 import sys
-import decimal
-import datetime
+import pickle
 
 from django.template import Template, Context
 from django.conf import settings
@@ -41,6 +42,12 @@
         s4 = ugettext_lazy('Some other string')
         self.assertEqual(False, s == s4)
 
+    def test_lazy_pickle(self):
+        s1 = ugettext_lazy("test")
+        self.assertEqual(unicode(s1), "test")
+        s2 = pickle.loads(pickle.dumps(s1))
+        self.assertEqual(unicode(s2), "test")
+
     def test_string_concat(self):
         """
         unicode(string_concat(...)) should not raise a TypeError - #4796

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to