Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error in release 1.0 (Archetypes support, SearchableText): map built-in requires 2nd argument #8

Open
tobiasherp opened this issue May 6, 2024 · 1 comment

Comments

@tobiasherp
Copy link

Sorry I'm late for the party, but I still have a Plone 4.3 instance with Archetypes content ...

When I tried to save an object with the package activated, I found the SearchableText patch to fail:

Traceback (innermost last):
  ...
  Module Products.ZCTextIndex.ZCTextIndex, line 184, in index_object
  Module experimental.gracefulblobmissing.patches, line 107, in patched_SearchableText
**TypeError: map() requires at least two args**

I shortened this a bit because the cause is truly local:
In this code:

                # Unmangle vocabulary: we index key AND value
                vocab_values = map(                       # A
                    lambda value, vocab=vocab: (          # B
                        vocab.getValue(value, ''),
                        datum
                    )                                     # B
                )                                         # A

we have really just one argument to the map internal function.
As Python 2.7 puts it, at least; and that's the interpreter which is most likely to run this code.

I have a patch which takes the respective code block from Archetypes v1.9.21 and fixes the issue (for me, at least):

Index: experimental/gracefulblobmissing/patches.py
===================================================================
--- experimental/gracefulblobmissing/patches.py (revision 54244)
+++ experimental/gracefulblobmissing/patches.py (working copy)
@@ -101,17 +101,18 @@
             datum = ''
         if datum:
             vocab = field.Vocabulary(self)
-            if isinstance(datum, list) or isinstance(datum, tuple):
+            # ------------ [ code from Products.Archetypes v1.9.21 ... [
+            if isinstance(datum, (list, tuple)):
                 # Unmangle vocabulary: we index key AND value
-                vocab_values = map(
-                    lambda value, vocab=vocab: (
-                        vocab.getValue(value, ''),
-                        datum
-                    )
-                )
+                vocab_values = map(lambda value, vocab=vocab: vocab.getValue(value, ''), datum)
+                vocab_values = [
+                    v.encode('utf-8') if isinstance(v, unicode) else v
+                    for v in vocab_values
+                ]
                 datum = list(datum)
                 datum.extend(vocab_values)
                 datum = ' '.join(datum)
+            # ------------ ] ... code from Products.Archetypes v1.9.21 ]
             elif isinstance(datum, basestring):
                 # Note: this patched function is only used in Archetypes,
                 # so the Python2-only code is fine.

Sadly I couldn't find a branch, tag or whatever where to put it in this repo.

Could we have a bugfix release 1.1, please?
Otherwise I'd need to use a "local" release.

@mauritsvanrees
Copy link
Member

I have created a branch 1.x. You could make a PR for that branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants