Skip to content

fix: resolve UnboundLocalError in apm prune crashing all prune operations#283

Merged
danielmeppiel merged 2 commits intomainfrom
copilot/66955159225-fix-github-actions-workflow
Mar 13, 2026
Merged

fix: resolve UnboundLocalError in apm prune crashing all prune operations#283
danielmeppiel merged 2 commits intomainfrom
copilot/66955159225-fix-github-actions-workflow

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

apm prune failed unconditionally with cannot access local variable 'get_lockfile_path' where it is not associated with a value, breaking all prune-related integration tests.

Description

A duplicate from ..deps.lockfile import get_lockfile_path inside the prune() function body shadowed the module-level import. Python treats any name assigned (including via import) within a function as local throughout the entire function scope — causing an UnboundLocalError when the name was referenced earlier in the same function, before the inner import statement was reached.

# Before — duplicate inner import made `get_lockfile_path` an unbound local
from ..deps.lockfile import LockFile, get_lockfile_path  # module-level

def prune(...):
    lockfile = LockFile.read(get_lockfile_path(...))  # UnboundLocalError here ↑
    ...
    if pruned_keys:
        from ..deps.lockfile import get_lockfile_path   # ← this shadowed the module import
        lockfile_path = get_lockfile_path(...)

Fix: remove the redundant inner import; the module-level import is sufficient.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
Original prompt

Fix the failing GitHub Actions workflow Integration Tests (Linux)
Analyze the workflow logs, identify the root cause of the failure, and implement a fix.
Job ID: 66955159225
Job URL: https://github.com/microsoft/apm/actions/runs/23051934848/job/66955159225


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…boundLocalError

Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com>
Copilot AI changed the title [WIP] [66955159225] Fix failing GitHub Actions workflow integration tests fix: resolve UnboundLocalError in apm prune crashing all prune operations Mar 13, 2026
Copilot AI requested a review from danielmeppiel March 13, 2026 13:14
@danielmeppiel danielmeppiel marked this pull request as ready for review March 13, 2026 13:20
Copilot AI review requested due to automatic review settings March 13, 2026 13:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes a redundant local import in the apm prune command, relying on the existing module-level import for get_lockfile_path.

Changes:

  • Remove the nested from ..deps.lockfile import get_lockfile_path import inside the if pruned_keys: block.

@danielmeppiel danielmeppiel merged commit 66d7853 into main Mar 13, 2026
22 checks passed
@danielmeppiel danielmeppiel deleted the copilot/66955159225-fix-github-actions-workflow branch March 13, 2026 13:53
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.

3 participants