Skip to content

Commit

Permalink
Python 3/Plone 5.2: UTF-8-encode paths when traversing with python 2.
Browse files Browse the repository at this point in the history
Workaround for zopefoundation/Zope#674
Fixes TypeError: 'int' object is not subscriptable
  • Loading branch information
reinhardt committed Jul 23, 2019
1 parent ed28847 commit d3a4495
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/collective/solr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ def findObjects(origin):
the given start point """
traverse = origin.unrestrictedTraverse
base = '/'.join(origin.getPhysicalPath())
if isinstance(base, six.text_type):
base = base.encode('utf-8')
cut = len(base) + 1
paths = [base]
for idx, path in enumerate(paths):
if six.PY2:
path = path.encode('utf-8')
obj = traverse(path)
if six.PY2:
path = path.decode('utf-8')
yield path[cut:], obj
if hasattr(aq_base(obj), 'objectIds'):
for id in obj.objectIds():
if isinstance(id, six.text_type):
id = id.encode('utf-8')
paths.insert(idx + 1, path + b'/' + id)
paths.insert(idx + 1, path + '/' + id)


def padResults(results, start=0, **kw):
Expand Down

2 comments on commit d3a4495

@ale-rt
Copy link
Member

@ale-rt ale-rt commented on d3a4495 Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think base as defined in line 193 should always be a native string.

So line 194 and 195 should be removed as done in this commit.
After that is done I am not sure lines 197 and 198 are needed and so lines 200 and 201.

Also objectIds() should return native strings.
If not line 205 should be paths.insert(idx + 1, path + '/' + safe_nativestring(id)).

It seems to me that master version of this function should already work, but of course I am missing something :)

def findObjects(origin):

@reinhardt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be damned, I can't reproduce the issue any more. Was probably caused by something else that has been fixed in the meantime. I'm removing the workaround; thanks for pointing it out!

Please sign in to comment.