Skip to content

Commit

Permalink
Fixing false positive key paths containing None.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Dec 30, 2014
1 parent 03f5dd8 commit 16760fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ def _parse_path(path_args):

kind_list = path_args[::2]
id_or_name_list = path_args[1::2]
# Dummy sentinel value to pad incomplete key to even length path.
partial_ending = object()
if len(path_args) % 2 == 1:
# Add dummy None to be ignored below.
id_or_name_list += (None,)
id_or_name_list += (partial_ending,)

result = []
for kind, id_or_name in izip(kind_list, id_or_name_list):
Expand All @@ -106,7 +107,7 @@ def _parse_path(path_args):
curr_key_part['name'] = id_or_name
elif isinstance(id_or_name, six.integer_types):
curr_key_part['id'] = id_or_name
elif id_or_name is not None:
elif id_or_name is not partial_ending:
raise ValueError(id_or_name,
'ID/name was not a string or integer.')

Expand Down
2 changes: 2 additions & 0 deletions gcloud/datastore/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def test_ctor_bad_kind(self):

def test_ctor_bad_id_or_name(self):
self.assertRaises(ValueError, self._makeOne, 'KIND', object())
self.assertRaises(ValueError, self._makeOne, 'KIND', None)
self.assertRaises(ValueError, self._makeOne, 'KIND', 10, 'KIND2', None)

def test__clone(self):
_DATASET = 'DATASET'
Expand Down

0 comments on commit 16760fb

Please sign in to comment.