Re: zope-tests - FAILED: 2, OK: 20, UNKNOWN: 1

Gediminas Paulauskas <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <CAFuCVqNjyaCA2Bo+UfNVioCVNzrkYQ4zXfA1+dvVp9-QgADAXg@mail.gmail.com>
2012/12/7 Tres Seaver <[email protected]>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 12/07/2012 01:52 AM, Marius Gedminas wrote:
>>>> [3]    FAILED  winbot / zope.app.i18n_py_265_32
>>>> https://mail.zope.org/pipermail/zope-tests/2012-December/069796.html
>>
>>>>
> Error in test testNoTargetLanguage
> (zope.app.i18n.tests.test_translationdomain.TestTranslationDomain)
>> Traceback (most recent call last): File
>> "c:\Python26_32\lib\unittest.py", line 279, in run testMethod() File
>> "c:\eggs\zope.i18n-3.8.0-py2.6.egg\zope\i18n\tests\test_itranslationdomain.py",
>> line 99, in testNoTargetLanguage eq(translate('short_greeting',
>> context=context, default=42), 42) File
>> "c:\buildslave\zope.app.i18n\build\src\zope\app\i18n\translationdomain.py",
>> line 74, in translate catalog_names =
>> self._catalogs.get(target_language, []) TypeError: Object has default
>> comparison
>
> Here, the 'target_langeage' returned by the negotiator is None, which the
> OOBTree is refusing to treat as a key (because its comparison semantics
> are undefined across process boundaries / Python versions)::
>
>  >>> from BTrees.OOBTree import OOBTree
>  >>> x = OOBTree()
>  >>> x[None] = 1
>  Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>  TypeError: Object has default comparison
>
> Such keys haven't been allowed since::
>
>  r117933 | jim | 2010-10-26 17:14:00 -0400 (Tue, 26 Oct 2010) | 7 lines
>
>  Bug Fixed
>  - BTrees allowed object keys with insane comparison. (Comparison
>    inherited from object, which compares based on in-process address.)
>    Now BTrees raise TypeError is an attempt is made to save a key with
>    comparison inherited from object. (This doesn't apply to old-style
>    class instances.)

The error happens in get, not set, should it?

Otherwise, a patch for zope.app.i18n to fix this case is attached (not
committed).

-- 
Gediminas

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
zopeappi18n-with-zodb4.diff (application/octet-stream, 1.3 KB)
Index: CHANGES.txt
===================================================================
--- CHANGES.txt	(revision 128543)
+++ CHANGES.txt	(working copy)
@@ -5,9 +5,8 @@
 3.6.4 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- Fix translate() when used with ZODB 4.
 
-
 3.6.3 (2010-09-01)
 ------------------
 
Index: src/zope/app/i18n/translationdomain.py
===================================================================
--- src/zope/app/i18n/translationdomain.py	(revision 128543)
+++ src/zope/app/i18n/translationdomain.py	(working copy)
@@ -23,7 +23,6 @@
 import zope.component
 from zope.interface import implements
 from zope.i18n import interpolate
-from zope.i18n.negotiator import negotiator
 from zope.i18n.interfaces import INegotiator, ITranslationDomain
 from zope.i18n.simpletranslationdomain import SimpleTranslationDomain
 
@@ -71,7 +70,10 @@
             target_language = negotiator.getLanguage(avail_langs, context)
 
         # Get the translation. Default is the source text itself.
-        catalog_names = self._catalogs.get(target_language, [])
+        if target_language is not None:
+            catalog_names = self._catalogs.get(target_language, [])
+        else:
+            catalog_names = []
 
         for name in catalog_names:
             catalog = super(TranslationDomain, self).__getitem__(name)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.