Repository navigation
Fix chain/group repr mangling task names and arguments - #10855
Conversation
remove_repeating_from_task() removed every occurrence of the first task's module prefix from the rest of the repr, including in the middle of other names: with 'app.tasks.add' first, 'webapp.tasks.mul' was shown as 'webmul'. When the first task name had no module (e.g. 'add') the prefix became '.', so every following dot was removed, turning 'proj.tasks.mul(2.5)' into 'projtasksmul(25)'. Only strip the prefix where it starts a name, and do nothing when the task name has no module part. Signed-off-by: Guillaume Marty <[email protected]>
|
is there any existing issue for this pr? if not not need to open one |
|
No existing issue that I know . |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10855 +/- ##
=======================================
Coverage 90.47% 90.48%
=======================================
Files 153 153
Lines 21277 21287 +10
Branches 2590 2593 +3
=======================================
+ Hits 19251 19261 +10
Misses 1710 1710
Partials 316 316
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
auvipy
left a comment
There was a problem hiding this comment.
please check the failures in CI
MehrazRumman
left a comment
There was a problem hiding this comment.
Ran this locally against main at 5a635c2.
CI
The one red job, Smoke-tests (t/smoke/tests/test_worker_shutdown_acks.py) / 3.12, failed in apt-get update before any test started:
E: Failed to fetch https://dl.google.com/linux/chrome-stable/deb/dists/stable/main/binary-amd64/Packages.gz File has unexpected size (1412 != 1408). Mirror sync in progress?
The other 59 smoke jobs were cancelled as a result. It is a runner mirror problem, not this change; a re-run should clear it.
What checks out
t/unit/utils/test_text.py and t/unit/tasks/test_canvas.py pass (330 passed, 1 xfailed). Both cases from the description are fixed, and since group and chord use the same helper their reprs are fixed too:
main this branch
chain app.tasks.a(1) | webmul(3) app.tasks.a(1) | webapp.tasks.mul(3)
chain add(1.5) | projtasksmul(25) add(1.5) | proj.tasks.mul(2.5)
group group((app.tasks.a(1), webb(2), c(3))) group((app.tasks.a(1), webapp.tasks.b(2), c(3)))
chord %tsum([p.qa(15), pqb(05)]) %tsum([p.q.a(1.5), p.q.b(0.5)])
Two cases still left (same output on main, so neither is a regression)
-
A module name ending in
-<prefix>: withapp.tasks.afirst,my-app.tasks.b()is shown asmy-b(). Adding-to the lookbehind covers it:re.sub(r'(?<![\w.-])' + re.escape(substr), '', ...)
-
String arguments that contain the prefix are still rewritten:
>>> tasks.add.s(1) | tasks.mul.s('tasks.report.csv') tasks.add(1) | mul('report.csv')
The regex can't tell a task name from a quoted value once everything is joined into one string, so this needs the shortening to happen per task name before joining. Fine as a follow-up.
Optional: the new test only exercises the helper. One repr() assertion for a group or chord in t/unit/tasks/test_canvas.py would pin the behaviour where users see it.
As suggested in review: "my-app.tasks.b" was shortened to "my-b" when "app.tasks." was the first task's module. Also pin the fix where users see it with a group repr test. Signed-off-by: Guillaume Marty <[email protected]>
…/LemonCondor/celery into fix/canvas-repr-remove-repeating
|
Thanks @auvipy and @MehrazRumman! The red smoke jobs failed in
The quoted-argument case ( |
|
@GangEunzzang @phanky1 please have a final look |
|
Looks good to me. Both of Mehraz's points are in ( I compared
Every difference from The new tests fail on Minor: |
@LemonCondor may be the last things to improve. |
Replace the per-call regex with str.split and a check of the character before each occurrence. The output is identical (checked against the regex version on 200,000 random strings), and repr() of a canvas nested 250 levels deep goes from 31 ms back to 13 ms (12 ms on main). Signed-off-by: Guillaume Marty <[email protected]>
|
Thanks @GangEunzzang for the thorough comparison, and @auvipy! I've pushed a change for the nested-canvas slowdown:
The quoted-value case ( |
Note: Before submitting this pull request, please review our contributing
guidelines.
Description
repr()of achain/groupshortens later task names by removing the first task's module prefix withremove_repeating_from_task(), which usesstr.replace()on the rest of the string. Two cases produce wrong output:app.tasks.afirst,webapp.tasks.mul(3)is shown aswebmul(3).add), the prefix is".", so every later dot is removed, including in arguments:This only affects
repr()/log output, but it shows wrong task names and argument values.The fix returns the string unchanged when the task name has no module, and only strips the prefix where it starts a name (not when preceded by a word character or a dot).
t/unit/utils/test_text.py::test_remove_repeating_from_taskcovers the two docstring examples and both cases above; the two new cases fail on main.t/unit/utils/test_text.pyandt/unit/tasks/test_canvas.pypass (319 passed, 1 xfailed); flake8/isort clean.