collective / collective/experimental.gracefulblobmissing

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

Open
#8 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in experimental/gracefulblobmissing/patches.py around patched_SearchableText at line 107, and compare the vocabulary-handling block with the supplied Products.Archetypes v1.9.21 code. Verify the fix while saving an Archetypes object under Python 2.7; done means SearchableText indexing no longer raises the map() TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.