Skip to content

docs: note unique_id ignores requires() dict keys and non-gokart luigi.Task class names - #692

Open
hirosassa wants to merge 3 commits into
masterfrom
docs/unique-id-identity-caveats
Open

hirosassa wants to merge 3 commits into
masterfrom
docs/unique-id-identity-caveats

Conversation

@hirosassa

@hirosassa hirosassa commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #682

Summary

Added a note to docs/task_on_kart.rst about what is excluded from make_unique_id() (no changes to code behavior).

  • Dict key names returned by requires() are not included in unique_id (_make_hash_id hashes only the values from flatten(self.requires()) in order).
  • Non-gokart luigi.Task dependencies do not include their class names (TaskOnKart dependencies do because they use their own make_unique_id()).
  • As a result, changing dependency targets or key mappings does not change the output path, which can cause stale cache reuse. Workarounds are a significant version parameter or serialized_task_definition_check=True (rerun=True only re-runs the task itself).
    Verification
  • Verified the claims against the actual behavior of _make_hash_id in gokart/task.py and gokart.utils.flatten (a copy of luigi.task.flatten).
  • Checked with docutils that there are no warnings in the added section, as sphinx-build could not complete locally due to pandas import hanging. ruff and pyright passed.
  • pytest was not run to completion locally (docs-only change).

🤖 Generated with Claude Code

…i.Task class names

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@kitagry kitagry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I checked both claims against _make_hash_id and gokart.utils.flatten, and both hold: renaming the keys of requires() (or swapping which key maps to which task while keeping the order of the values) keeps the id, and so does swapping a plain luigi.Task / ExternalTask dependency for another class with the same significant parameters. With gokart.build the second run returns the stale output of the first one, so the warning is worth having. The RST builds with no new Sphinx warnings.

Some suggestions, mostly on the workarounds:

  1. rerun=True does not fix the tasks downstream. rerun is significant=False, so it does not change make_unique_id(). A task that depends on the rewired task keeps its old output, and since that downstream task is already complete, the task with rerun=True is not even scheduled. In my check, Final -> Sub(rerun=True) still returned the old result after rewiring Sub.requires(), while Sub(serialized_task_definition_check=True) changed Sub's id and Final re-ran. docs/task_settings.rst ("rerun" section) already explains this and recommends adding or bumping a significant parameter (e.g. a version parameter) instead. Could the note point there, along these lines?

    To avoid this, set serialized_task_definition_check=True, or add a significant parameter (e.g. a version) and change it when you change requires() (see :doc:task_settings). rerun=True only re-runs the task itself; it does not change the hash, so tasks that depend on it keep their existing outputs.

  2. What serialized_task_definition_check=True hashes. get_own_code() collects the source of the methods of the class only. If requires() uses a class attribute (e.g. dep_cls = LA and return {'ext': self.dep_cls()}), changing it to dep_cls = LB keeps the id, and the stale output is reused. The same applies to module-level helpers or aliases and to changes inside the dependency class. Maybe "the source code of the methods of the task, including requires(), is then hashed (class attributes and code outside the class are not)". It is also worth saying that turning it on changes the id (so the existing outputs of this task and its downstream tasks are recomputed once), and that any later edit to a method, even in run(), does the same.

  3. Scope of the dict-key caveat. It applies to a hand-written requires(). With the default requires() (dependencies passed as TaskInstanceParameter), the keys are the parameter names, and they are hashed through the task's own parameters: D(a=X(), b=Y()) and D(a=Y(), b=X()) get different ids. Saying "a dict returned by an overridden requires()" would avoid scaring users of the common pattern.

  4. "which includes its class name" is only the bare __class__.__name__ (no module, no namespace). Two same-named TaskOnKart classes from different modules with the same parameters get the same id, so swapping the import in requires() has the same problem as the plain luigi.Task case. A dependency with significant=False is dropped from the hash entirely. Maybe worth a short mention, since the note reads as the list of what is not included.

  5. (nit, optional) Only the flattened values are hashed, so the container shape is not part of the id either ({'a': X(), 'b': Y()}, [X(), Y()], (X(), Y()), nested dicts, and X() vs [X()]). And the other way round, reordering the entries of the dict without changing the mapping does change the id and re-runs the task.

  6. (question) #682 lists hashing the keys / the class name as possible fixes. Should this PR use Refs #682 instead of Closes #682, so the fix can still be considered for 2.0.0 (#685)? Fine either way if documenting it is the decision.

Minor: the added block leaves three blank lines before the TaskOnKart.load heading (two elsewhere). In the PR description, _make_hash_id uses gokart.utils.flatten (a copy of luigi.task.flatten), not luigi.task.flatten itself; it behaves the same for dicts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hirosassa

Copy link
Copy Markdown
Collaborator Author

Thanks for the careful review! All addressed in the latest commit:

  1. Workaround now points to a significant (version) parameter, linking :doc:task_settings, and says rerun=True only re-runs the task itself and does not change the hash.
  2. serialized_task_definition_check=True: now says only the source of the task's methods is hashed (class attributes, code outside the class and changes inside a dependency class are not), and that turning it on changes the id once and any later method edit does the same.
  3. The dict-key caveat is scoped to an overridden requires(), and notes the default TaskInstanceParameter pattern hashes parameter names.
  4. Class name is described as the bare __class__.__name__, with the same-named-classes-from-different-modules case and significant=False dependencies.
  5. Added the container-shape and entry-reordering nit.
  6. Switched to Refs #682 so the fix can still be considered for 2.0.0 (2.0.0 removals #685).

Also fixed the blank-line count before the TaskOnKart.load heading and the flatten reference in the description. Note: I could not run a Sphinx build locally, so the :doc: link is unchecked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants