humbledb icon indicating copy to clipboard operation
humbledb copied to clipboard

Slicing for lists are broken

Open xni opened this issue 9 years ago • 0 comments

Hey!

Thank you for your great project, we use it in a very extensive way and really like it. But recently we faced with a problem I want to complain about.

Snippet for the problem: https://gist.github.com/xni/312880df3ec52d10a80d Idea is: when you are trying to get some items from a ListMap, you receive not DictMaps but native dicts. Seems that the problem is in https://github.com/shakefu/humbledb/blob/master/humbledb/maps.py#L235 - when the result is not a dict, but list, no conversion is performed.

I suggest that kind of a solution:

    def __getitem__(self, index):
        value = super(ListMap, self).__getitem__(index)
        # Only create a new DictMap if we actually map into this list
        if isinstance(value, dict) and not self._name_map.empty():
            value = DictMap(value, self._name_map, self, None,
                    self._reverse_name_map)
        elif isinstance(value, list) and not self._name_map.empty():
            value = (DictMap(obj, self._name_map, self, None,
                             self._reverse_name_map)
                     for obj in value)
        return value

but I am not confident, because I don't have a deep understanding of a project.

We need your help very much! Thank you!

xni avatar Feb 15 '16 13:02 xni