Skip to content

Commit 8bb779f

Browse files
author
Chris Rossi
authored
fix: fix bug with yield of empty list in tasklets (#354)
`yield` of an empty list will no longer cause a tasklet to hang forever. Fixes #353.
1 parent 5ce40ba commit 8bb779f

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

packages/google-cloud-ndb/google/cloud/ndb/tasklets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ def __init__(self, dependencies):
411411
for dependency in dependencies:
412412
dependency.add_done_callback(self._dependency_done)
413413

414+
if not dependencies:
415+
self.set_result(())
416+
414417
def __repr__(self):
415418
return "{}({}) <{}>".format(
416419
type(self).__name__,

packages/google-cloud-ndb/tests/system/test_misc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ def test_pickle_roundtrip_structured_property(dispose_of):
5656
assert entity.other.key is None or entity.other.key.id() is None
5757
entity = pickle.loads(pickle.dumps(entity))
5858
assert entity.other.foo == 1
59+
60+
61+
@pytest.mark.usefixtures("client_context")
62+
def test_tasklet_yield_emtpy_list():
63+
"""
64+
Regression test for Issue #353.
65+
66+
https://github.com/googleapis/python-ndb/issues/353
67+
"""
68+
69+
@ndb.tasklet
70+
def test_it():
71+
nothing = yield []
72+
raise ndb.Return(nothing)
73+
74+
assert test_it().result() == ()

packages/google-cloud-ndb/tests/unit/test_tasklets.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ def test_cancel():
453453
with pytest.raises(exceptions.Cancelled):
454454
future.result()
455455

456+
@staticmethod
457+
def test_no_dependencies():
458+
future = tasklets._MultiFuture(())
459+
assert future.result() == ()
460+
456461

457462
class Test__get_return_value:
458463
@staticmethod

0 commit comments

Comments
 (0)