projecteru / redis-trib.py

Redis Cluster lib in Python
MIT License
135 stars 45 forks source link

Problem slicing in function _add_slots() in pypy 7.0.0 (Python 2.7.13) #16

Closed evernetsoftware closed 3 years ago

evernetsoftware commented 4 years ago

Stumbled on this yesterday and took some time to find as the code looked fine and required debugging to see the issue. Basically it seems like pypy converts uses of range to xrange in the background. This surfaces as an issue in the function _add_slots which is attempts to slice the list of slots provided to it by the _add_slots_range function supply a range as the slots_list parameter, yet pypy silently overriding this with xrange blows up as you can slice a generator.

Note: this is using redistrib version 0.6.1 installed via pip in virtualenv on Ubuntu 19.04

Attached two images to make it clear, along with my monkey patch hack to fix the issue quickly - though I'm sure someone else can do better. Problem Solution

zheplusplus commented 4 years ago

Thanks for reporting. Let me have a look

zheplusplus commented 4 years ago

In this file range is patched by six which is xrange in Python2 and range in Python3. The issue is that xrange does not support slicing.

Would appreciate if you can also take a look at PR #17 if it solves the problem.

Please let me know if any further concern.