Skip to content

Commit 6fd0d35

Browse files
xirdnehOmer Katz
authored andcommitted
Fixes issue 4768. (celery#4790)
* Returning GroupResult's parent as tuple for correct serialization * Adding test task to return a GropuResult * Change assert to check parent is tuple and not the id because of change for issue celery#4768 * Add previously deleted assert to check the parent id is in the rult tuple, and to avoid coverage decrease
1 parent 23401ba commit 6fd0d35

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

celery/result.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,10 @@ def __repr__(self):
918918
', '.join(r.id for r in self.results))
919919

920920
def as_tuple(self):
921-
return (self.id, self.parent), [r.as_tuple() for r in self.results]
921+
return (
922+
(self.id, self.parent and self.parent.as_tuple()),
923+
[r.as_tuple() for r in self.results]
924+
)
922925

923926
@property
924927
def children(self):

t/integration/tasks.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,23 @@ def second_order_replace2(self, state=False):
158158
raise self.replace(new_task)
159159
else:
160160
redis_connection.rpush('redis-echo', 'Out B')
161+
162+
163+
@shared_task(bind=True)
164+
def build_chain_inside_task(self):
165+
"""Task to build a chain.
166+
167+
This task builds a chain and returns the chain's AsyncResult
168+
to verify that Asyncresults are correctly converted into
169+
serializable objects"""
170+
test_chain = (
171+
add.s(1, 1) |
172+
add.s(2) |
173+
group(
174+
add.s(3),
175+
add.s(4)
176+
) |
177+
add.s(5)
178+
)
179+
result = test_chain()
180+
return result

t/integration/test_canvas.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
from .conftest import flaky, get_active_redis_channels, get_redis_connection
1212
from .tasks import (add, add_chord_to_chord, add_replaced, add_to_all,
13-
add_to_all_to_chord, collect_ids, delayed_sum,
14-
delayed_sum_with_soft_guard, identity, ids, print_unicode,
15-
redis_echo, second_order_replace1, tsum)
13+
add_to_all_to_chord, build_chain_inside_task, collect_ids,
14+
delayed_sum, delayed_sum_with_soft_guard, identity, ids,
15+
print_unicode, redis_echo, second_order_replace1, tsum)
1616

1717
TIMEOUT = 120
1818

@@ -188,6 +188,20 @@ def test_chain_error_handler_with_eta(self, manager):
188188
result = c.get()
189189
assert result == 10
190190

191+
@flaky
192+
def test_groupresult_serialization(self, manager):
193+
"""Test GroupResult is correctly serialized
194+
to save in the result backend"""
195+
try:
196+
manager.app.backend.ensure_chords_allowed()
197+
except NotImplementedError as e:
198+
raise pytest.skip(e.args[0])
199+
200+
async_result = build_chain_inside_task.delay()
201+
result = async_result.get()
202+
assert len(result) == 2
203+
assert isinstance(result[0][1], list)
204+
191205

192206
class test_result_set:
193207

t/unit/tasks/test_result.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,10 @@ def test_GroupResult_as_tuple(self):
10051005
for i in range(2)],
10061006
parent
10071007
)
1008-
(result_id, parent_id), group_results = result.as_tuple()
1008+
(result_id, parent_tuple), group_results = result.as_tuple()
10091009
assert result_id == result.id
1010-
assert parent_id == parent.id
1010+
assert parent_tuple == parent.as_tuple()
1011+
assert parent_tuple[0][0] == parent.id
10111012
assert isinstance(group_results, list)
10121013
expected_grp_res = [(('async-result-{}'.format(i), None), None)
10131014
for i in range(2)]

0 commit comments

Comments
 (0)