Skip to content

Debugging our pipeline code

Debugging with VS Code

Setup

  1. Create or modify .vscode/launch.json in your project root:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "kedro run",
            "type": "debugpy",
            "request": "launch",
            "module": "kedro",
            "args": ["run"],
            "cwd": "${workspaceFolder}/pipelines/your_pipeline"
        }
    ]
}

Common Debug Configurations

Here are some useful debug configurations for Kedro:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run Full Pipeline",
            "type": "debugpy",
            "request": "launch", 
            "module": "kedro",
            "args": ["run"],
            "cwd": "${workspaceFolder}/pipelines/your_pipeline"
        },
        {
            "name": "Run Specific Nodes",
            "type": "debugpy",
            "request": "launch",
            "module": "kedro",
            "args": ["run", "--nodes", "node1,node2"],
            "cwd": "${workspaceFolder}/pipelines/your_pipeline"
        },
        {
            "name": "Run with Different Env",
            "type": "debugpy", 
            "request": "launch",
            "module": "kedro",
            "args": ["run", "-e", "test"],
            "cwd": "${workspaceFolder}/pipelines/your_pipeline"
        }
    ]
}

Using the Debugger

  1. Set breakpoints by clicking to the left of the line numbers in your code
  2. Select your debug configuration from the dropdown in the Debug view
  3. Start debugging by pressing F5 or clicking the green play button

Debug Variables and Watch

  • Use the Variables pane to inspect local and global variables
  • Add expressions to the Watch pane to monitor specific values
  • Use the Debug Console to evaluate expressions in the current context

Advanced Debugging

Node-specific Debugging

To debug specific nodes in your pipeline:

{
    "name": "Debug Specific Node",
    "type": "debugpy",
    "request": "launch",
    "module": "kedro",
    "args": ["run", "--nodes", "target_node"],
    "cwd": "${workspaceFolder}/pipelines/your_pipeline"
}

Pipeline Slicing

Debug a slice of your pipeline:

{
    "name": "Debug Pipeline Slice",
    "type": "debugpy",
    "request": "launch",
    "module": "kedro",
    "args": ["run", "--from-nodes", "start_node", "--to-nodes", "end_node"],
    "cwd": "${workspaceFolder}/pipelines/your_pipeline"
}

Additional Resources

Tips and Tricks

  1. Use conditional breakpoints by right-clicking on a breakpoint
  2. Enable "Just My Code" to avoid stepping into library code
  3. Use logpoints for non-breaking debugging messages
  4. Utilize the "Debug Console" for interactive debugging

Common Issues

  1. Missing debugpy: Ensure debugpy is installed in your environment
    pip install debugpy
    
  2. Wrong Working Directory: Make sure the cwd in launch.json points to your pipeline directory
  3. Environment Issues: Verify VS Code is using the correct Python interpreter with your Kedro environment