Skip to content

pdd update --output crashes with NameError when code file is in subdirectory #493

@Serhan-Asad

Description

@Serhan-Asad

Description

pdd update <code_file> --output <path> crashes with NameError when the code file is in a subdirectory.

Reproduction

mkdir -p /tmp/pdd-test/backend/src
echo "def hello(): return 'world'" > /tmp/pdd-test/backend/src/module.py
cd /tmp/pdd-test && git init && git add -A && git commit -m "init"
pdd update backend/src/module.py --output /tmp/output/

Actual output

Error: cannot access local variable 'context_config' where it is not associated with a value

Root cause

In pdd/update_main.py, line 75 defines context_config inside the else branch (when --output is NOT provided). But line 91 uses context_config.get("generate_output_path", "") unconditionally — including when --output IS provided, causing a NameError.

# Line 70-80
if output_dir:
    base_prompts_dir = os.path.abspath(output_dir)  # context_config never set
else:
    context_name, context_config = detect_context_for_file(...)  # only defined here

# Line 91 — reached regardless
code_root = context_config.get("generate_output_path", "")  # NameError if --output was used

Only triggers when the code file is in a subdirectory (so rel_dir != "." at line 85).

Suggested fix

Default context_config = {} before the if/else branch so .get() returns the fallback value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions