Repository navigation
fix!: raise GokartBuildError for MISSING_EXT and NOT_RUN in gokart.build - #684
Conversation
kitagry
left a comment
There was a problem hiding this comment.
Thanks for picking this up. Switching from a deny-list to an allow-list is the right direction. I checked it against luigi 3.8.1 and ran the new tests: all three fail on the base build.py and pass with this change, and test/test_build.py passes (22 passed).
1. SUCCESS_WITH_RETRY can still hide MISSING_EXT / NOT_RUN / SCHEDULING_FAILED (pre-existing, but the new comment claims otherwise)
luigi's _tasks_status checks ever_failed and not failed first. So if any task failed and then succeeded on a retry, luigi returns SUCCESS_WITH_RETRY even when other tasks are still waiting on a missing external input, were never run, or failed scheduling. I measured this with keep_alive=true and a task with retry_count:
| scenario | status | root complete | gokart.build (this PR) |
|---|---|---|---|
retried dep + missing ExternalTask (return_value=False) |
SUCCESS_WITH_RETRY | False | returns None |
same (return_value=True) |
SUCCESS_WITH_RETRY | False | raw FileNotFoundError |
retried dep + complete() raises |
SUCCESS_WITH_RETRY | False | returns None |
| retried dep + resource never granted | SUCCESS_WITH_RETRY | False | returns None |
base behaves the same way, so this PR does not cause it. But the new WHY comment ("only SUCCESS / SUCCESS_WITH_RETRY mean the requested task finished") isn't accurate. I'd reword it, for example:
# WHY: MISSING_EXT / NOT_RUN mean the requested task did not run. Note that luigi reports
# SUCCESS_WITH_RETRY even if other problems remain, as long as every failed task was retried successfully.The robust fix is to check the root task itself, as gokart/run.py (_run_with_retcodes) already does: root_task not in task_sets['completed'] and root_task not in task_sets['already_done']. It uses the worker's task history, so it needs no extra complete() I/O. I'm fine with doing that in a follow-up issue. If we do, it would be good to ship it in the same release as this PR, so users see one behavior change instead of two.
2. Release: I'd target 2.0.0
- gokart has no CHANGELOG. Release notes are the auto-generated "What's Changed" list of PR titles, with no
.github/release.ymlcategories, so the!in the title is not highlighted anywhere in the notes. - Recently we deprecate first and remove in 2.0.0: #550, #558, #605, #637, #646 and #459 all add a
DeprecationWarningorFutureWarning, and #685 collects the removals. Earlier 1.x releases did include breaking changes without a warning (#504 in v1.12.1, dropping Python 3.9 in v1.10.3), but that is the older practice. - master already has an unreleased breaking change,
build!: move redis to the optional extra gokart[redis](#642), so the next release from master is breaking anyway.
So my suggestion is to list this under "Breaking change candidates for 2.0.0" in #685 and merge it for 2.0.0. If we cut another 1.x release from master before that, a small 1.x change that emits a FutureWarning for MISSING_EXT / NOT_RUN ("this will raise GokartBuildError in 2.0.0") would match how we handled #459 and #646. The old behavior is a silent failure, so I don't think the warning is strictly necessary. Whichever release this goes in, please add a "Breaking changes" note to the release notes by hand, using the migration paragraph from this PR description.
3. Docs
docs/intro_to_gokart.rst:171 still says "When some tasks are failed, gokart.build raises GokartBuildError." Could you update it to say that it also raises when an external dependency is missing or a task was not run?
Nits (optional)
- The two MISSING_EXT tests differ only in
return_value. AsubTestloop over(True, False)would cover both. test_build_raises_on_not_runsits inTestBuildMissingExternal, and it mocksluigi.build. NOT_RUN can be reproduced for real withresources = {'r': 2}on a task and[resources] r=1, which also covers gokart's own worker.- Consider adding
status=result.statustoGokartBuildError. For MISSING_EXT / NOT_RUN,raised_exceptionsis empty, so callers can't tell "missing input" apart from "task crashed" without matching on the summary text.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nt and docs, reproduce NOT_RUN for real Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
7d4b3b4 to
51c6e54
Compare
|
Thanks for the thorough review! All addressed in 51c6e54:
Gate (ruff, format, pyright, |
kitagry
left a comment
There was a problem hiding this comment.
Thanks for the quick update. I re-checked everything in 51c6e54 and it all looks good:
- The WHY comment now says correctly that
SUCCESS_WITH_RETRYcan hide other problems, and points to #690. docs/intro_to_gokart.rstcovers the new raise cases andstatus.- The MISSING_EXT tests are merged with
subTest, and NOT_RUN is reproduced for real. statusis optional and comes last, so existingGokartBuildError(message, raised_exceptions)calls and subclasses keep working.- The 2.0.0 note is in #685.
I checked the tests locally. With the base build.py, the 5 new tests fail (both MISSING_EXT subtests fail, NOT_RUN fails with "GokartBuildError not raised", and both status tests fail). With this branch, test/test_build.py passes (23 passed) with -n 0, and with -n auto five times in a row.
LGTM. A few optional nits:
TestBuildNotRun.setUpcan go. luigi treats a resource that is not configured as having 1 unit (available_resources.get(resource, 1)inScheduler._has_resources), soresources = {'r': 2}alone already givesNOT_RUNwith an emptyraised_exceptions. I checked this without thesetUp. Dropping it also removes the global config change. Right now that change leaves an empty[resources]section behind, and if a value forralready existed, it deletes it instead of restoring it. A name nobody would configure, such as_gokart_test_not_run, would also keep a developer's ownluigi.cfgfrom interfering.- The NOT_RUN test could also assert
cm.exception.raised_exceptions == {}, as the MISSING_EXT test does, since the docs now promise this. - A small wording point on "
raised_exceptionsis empty" for MISSING_EXT / NOT_RUN.raised_exceptionsis created outside_build_task, so it keeps exceptions from earlier attempts acrossHasLockedTaskExceptionretries. In addition, SCHEDULING_FAILED also comes with an emptyraised_exceptions, because luigi emits BROKEN_TASK, not FAILURE. Saying thatraised_exceptionsholds the exceptions from failed task runs, and thatstatusis the authoritative signal, would be more accurate. Alternatively, create the dict inside_build_task.
Unrelated to this PR, and not a blocker: GokartBuildError can't be pickled. Exception.__reduce__ rebuilds it as cls(message), and raised_exceptions is required. So a GokartBuildError raised inside a multiprocessing / ProcessPoolExecutor worker turns into a TypeError in the parent. This is the same on master. I can open a separate issue for it.
|
Opened #701 for the pickling issue with |
…view Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the re-review! Addressed the optional nits in the latest commit:
ruff, format, pyright and |
gokart.buildnow raisesGokartBuildErrorfor everyLuigiStatusCodeother thanSUCCESS/SUCCESS_WITH_RETRY. PreviouslyMISSING_EXTandNOT_RUNwere silently treated as success.Who is affected: callers whose build currently ends with
MISSING_EXT(anExternalTaskdependency's output is missing, so the requested task never ran) orNOT_RUN. These calls used to return normally (None, or a later unrelatedload()error withreturn_value=True); they will now raiseGokartBuildError.Migration: make sure external dependencies exist before building, or catch
GokartBuildErrorwhere the old silent behavior was relied on. The newGokartBuildError.status(aluigi.LuigiStatusCode, defaultNone) lets callers tellMISSING_EXT/NOT_RUN(emptyraised_exceptions) apart from a crashed task; existingGokartBuildError(...)calls stay compatible.Summary
_build_taskingokart/build.pynow uses a success allow-list (SUCCESS,SUCCESS_WITH_RETRY) instead of a failure deny-list of three statuses.GokartBuildErrorgains an optionalstatusattribute.docs/intro_to_gokart.rstis updated.Tests
ExternalTaskoutput (return_valueTrue/False),NOT_RUNreproduced for real via resources, andstatuson the error.test/test_build.py: 22 passed;ruff,ruff format,pyrightclean.ProcessTaskInfoTesthangs); they are unrelated to this change, so please rely on CI for the full suite.Follow-ups
SUCCESS_WITH_RETRYwhile other problems remain): gokart.build: SUCCESS_WITH_RETRY can hide an incomplete root task; check the root task like gokart.run does #690Closes #681
🤖 Generated with Claude Code