Skip to content

Migrating from v1 to v2

The canonical v2 entry points are an eagerly executed function carrying the flow decorator and a ProcessingTemplate. Results come back as a RunReport; status, the per-tile results, warnings and errors are all read from that one schema. This guide does not ask you to throw your handler classes away in one step: it combines a mechanical conversion with a small amount of manual work.

1. Inspect the existing code

Take the following v1-style file as legacy.py.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import rdetoolkit.workflows as legacy_workflows


class TextHandler:
    def process(self, srcpaths, resource_paths):
        source = next(srcpaths.inputdata.glob("*.txt"))
        destination = resource_paths.struct / "structured.txt"
        destination.write_text(source.read_text(encoding="utf-8"), encoding="utf-8")


def custom_dataset_function(srcpaths, resource_paths):
    TextHandler().process(srcpaths, resource_paths)


if __name__ == "__main__":
    legacy_workflows.run(custom_dataset_function=custom_dataset_function)

migrate check is a read-only command that reports migration points. migrate apply is a dry run by default and prints the converted flow function. Only after reviewing it, pass --no-dry-run --out <another directory>. The input file is never rewritten in place.

1
2
$ python -m rdetoolkit migrate check legacy.py
$ python -m rdetoolkit migrate apply legacy.py

Constructs that cannot be converted, such as dynamic dispatch, are left behind as TODO(rdetoolkit-migrate). Even without a TODO, check the generated code's tests and output directory before adopting it.

2. The intermediate form: wiring handlers with as_node

An existing handler that satisfies an Appendix M Protocol can, for the migration period only, have a method turned into an ordinary node with as_node. The Protocol helps with this migration decision; it is not a DI mechanism and not an entry point for new designs.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from rdetoolkit import as_node


class LegacyReader:
    def read(self, name: str) -> str:
        return name.upper()


read_legacy = as_node(LegacyReader(), method="read", id="docs.migration.legacy_reader")
result = read_legacy("sample.txt")
assert result == "SAMPLE.TXT"

The class may stay at this stage, but pass values between nodes as explicit arguments and do not add hidden state such as self.df.

3. Choose the final form

If a domain template exists, check its slots with templates describe <name> and implement only the TODO slots of the class generated by init --processing-template <name>. The template owns the skeleton, the save order and the output conventions.

For irregular processing without a template, write one function with the flow decorator. if, loops, f-strings, literal arguments and default arguments behave exactly as in ordinary Python. Split work into functions with the node decorator only when you want to reuse it. Use the builtin nodes in rdetoolkit.nodes for saving.

Runtime changes

  • The canonical v2 return value is RunReport. Start from report.status and report.iterations.
  • On the flow entry point, on_iteration_error defaults to continue. If you need v1's immediate stop (fail-fast), set fail_fast explicitly. The v1 entry point run(custom_dataset_function=...) keeps v1's iteration rules (see "Intentional differences" below).
  • The graph is a call sequence recorded after execution, not a pre-execution DAG. Ordinary Python control flow works as is.

Compatibility scope and schedule for v1 users

This section is final as of 2.0.0rc1. The v1 execution path (the iteration loop and the per-mode processing) has been removed and every entry point runs through a single Runner. The v1 contract (entry point, artifacts, how a run ends) is protected by tests that compare against contract snapshots frozen from the v1 execution path carrying the v1.7.1 contract.

What is kept

  • Entry point: the signature of rdetoolkit.workflows.run(custom_dataset_function=...). The callback still receives (srcpaths, resource_paths).
  • The v1 contract: the returned JSON (the per-tile status list), SystemExit(1) on failure, fail-fast by default, the data/job.failed format, the output directory layout (raw/, structured/, divided/NNNN/ and so on), and data/logs/rdesys_<timestamp>.log.
  • Tier 1 API: rdetoolkit.models.rde2types, rdetoolkit.rde2util, rdetoolkit.invoicefile, rdetoolkit.errors, rdetoolkit.exceptions, workflows.check_files / check_files_result, and workflows.generate_folder_paths_iterator.
  • The existing CLI commands such as rdetoolkit init / gen-invoice / make-excelinvoice / artifact.

What was removed (2.0.0rc1)

  • The rdetoolkit.modeproc module.
  • The rdetoolkit.processing package (Pipeline, ProcessingContext, Processor and all of its subclasses).
  • The per-mode functions in rdetoolkit.workflows: invoice_mode_process, excel_invoice_mode_process, multifile_mode_process, rdeformat_mode_process and smarttable_invoice_mode_process.
  • The public impl and interfaces exports of the rdetoolkit package. Both modules remain as internals of the Runner but are not public API.

Code that imports any of these directly should go back to calling run(custom_dataset_function=...) or move to a flow function.

Deprecated (no caller left, kept only for compatibility): rdetoolkit.errors.handle_and_exit_on_structured_error and rdetoolkit.models.result.WorkflowResultManager. Do not use them in new code. The smarttable_rowfile= argument of RdeOutputResourcePath also remains, as in v1.7, a deprecated alias of smarttable_rawfile.

Behaviour changes

Introduced in the v1.7 line (unchanged in v2)

  • In SmartTable mode the row CSV (fsmarttable_*.csv) is not part of rawfiles (#503). Use smarttable_rawfile when you need the row CSV (the old name smarttable_rowfile was a misspelling and has been renamed).
  • With smarttable.save_table_file: true the original SmartTable file is registered first, as divided/0001, and the data rows move to divided/0002 onwards (#503).
  • A SmartTable meta/<key> column requires tasksupport/metadata-def.json. Without it the run fails with StructuredError instead of silently ignoring the column (#496).

Introduced in 2.0.0rc1

  • Every run writes an event log, data/logs/events_<run_id>.jsonl, by default. The file is capped at 64 MiB per run: when the cap is reached, warning W1002 (EventsLogTruncated) is recorded once and only the node-level events after that point are dropped (run-level and tile-level events and warnings are kept). data/logs/** is not part of the v1 artifact contract.
  • data/logs/iterations/ is emptied when tile iteration starts. job.failed, run_report_* and events_* are kept across runs, as before.

Intentional differences (cases where v2's result differs from v1)

Case v1 v2
The callback raises StructuredError(msg, ecode) ecode and msg in job.failed Same
The callback raises a plain exception ErrorCode=999, Unexpected error in <mode> mode: ... ErrorCode=3001. The message is the error-catalogue E3001 text and contains your exception's message
invoice.schema.json itself is invalid and the callback also fails The callback's error code (v1 validated after the callback) ErrorCode=4001 with the schema-validation reason. The callback is not called
The invoice violates its schema A mode-specific code; in some modes the callback had already run and outputs were created ErrorCode=4001. The callback is not called and no tile artifacts are created (job.failed, the logs and the run report remain)
Configuration discovery (config=None) Loaded from data/tasksupport Same. An invalid configuration file is ErrorCode=999, as in v1
Location of rdesys_<timestamp>.log data/logs Same for the standard layout
SIGTERM during a run The process simply dies; no job.failed, no record job.failed with ErrorCode=3004 (RunInterrupted), a RunReport is written, and the artifacts of completed tiles are kept. The public entry point exits with 1
Exit code of the rdetoolkit run CLI v1 had no run command 0 success / 1 failed / 2 partially failed / 3 usage error. The Python API run() behaves as in v1 (SystemExit(1) on failure)
multidata_tile.ignore_errors: true and every tile fails MultiDataTile only: returns JSON with every entry failed, exit code 0. Other modes ignore the flag and stop at the first failure The v1 callback entry point behaves as v1 in all modes. On the flow entry point, all tiles failing is failed and job.failed is written

Rollback

If v2 causes problems, pin 1.7.1, the latest v1 release (for example rdetoolkit==1.7.1 in requirements.txt). The development build that still contains the old execution path is not on PyPI; it can only be installed from source at the git tag v2.0.0a1 (for diagnosis only; that tag reports __version__ as 2.0.0).

Schedule

Releases go 2.0.0rc1 → GA 2.0.1. The version number 2.0.0 is skipped and will not be published as a final release.