From bcd20c7ecae292df9eca455e52c8c77638b185ca Mon Sep 17 00:00:00 2001 From: mwmajewsk <5279578+mmajewsk@users.noreply.github.com> Date: Wed, 20 Jun 2018 22:44:49 +0200 Subject: [PATCH] Update util.py - fix ensure_tuple instance check doing isinstance(obj, Sequence) makes calls with keys of dict impossible Example: Returns ``` d = {'a':'a', 'b':'b'} table.upsert(values, d.keys()) ``` `dict_keys(['a', 'b'])` is not of instance Sequence, but Iterable, therefore `ensure_tuple(dict_keys(['a', 'b']))` returns (dict_keys(['a', 'b']),) which leads to invalid iteration. --- dataset/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dataset/util.py b/dataset/util.py index 57fec8f..b1a0390 100644 --- a/dataset/util.py +++ b/dataset/util.py @@ -1,6 +1,6 @@ import six from hashlib import sha1 -from collections import OrderedDict, Sequence +from collections import OrderedDict, Iterable from six.moves.urllib.parse import urlparse QUERY_STEP = 1000 @@ -99,7 +99,7 @@ def ensure_tuple(obj): """Try and make the given argument into a tuple.""" if obj is None: return tuple() - if isinstance(obj, Sequence) and not isinstance(obj, six.string_types): + if isinstance(obj, Iterable) and not isinstance(obj, six.string_types): return tuple(obj) return obj,