Skip to content

fix: handle permission errors gracefully when writing package-lock.yml#12729

Open
claygeo wants to merge 2 commits into
dbt-labs:mainfrom
claygeo:fix/deps-lock-write-permission-error
Open

fix: handle permission errors gracefully when writing package-lock.yml#12729
claygeo wants to merge 2 commits into
dbt-labs:mainfrom
claygeo:fix/deps-lock-write-permission-error

Conversation

@claygeo
Copy link
Copy Markdown
Contributor

@claygeo claygeo commented Mar 29, 2026

Fixes #9241.

dbt deps fails with an unhandled PermissionError when run in a read-only directory (common in container environments with mounted project volumes). The lock() method tries to write package-lock.yml via open(lock_filepath, 'w'), which raises PermissionError; dbt exits with no output and no packages installed.

Fix

Wrap the lock-file write in a try/except OSError (which covers PermissionError, FileNotFoundError, etc.). On failure, fire a WARN-level log message and proceed — packages continue to install normally using packages.yml.

The warning is fired at EventLevel.WARN (not INFO) so it stands out in the console and structured log consumers can route it correctly.

Before: (silence — no packages installed, cryptic exit)

After:  [WARN] Could not write lock file at /project/package-lock.yml:
        [Errno 13] Permission denied. Proceeding without updating the lock file.
        ... (packages install normally)

The rest of dbt deps still works because load_yml_dict returns {} for missing files and the resolver falls back to packages.yml.

Checklist

  • My code follows the dbt coding conventions
  • I have signed the CLA
  • I have run this code in development and it appears to work correctly
  • I have added a changie entry

@claygeo claygeo requested a review from a team as a code owner March 29, 2026 03:01
@cla-bot cla-bot Bot added the cla:yes label Mar 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@github-actions github-actions Bot added the community This PR is from a community member label Mar 29, 2026
claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
@claygeo claygeo force-pushed the fix/deps-lock-write-permission-error branch 2 times, most recently from ec282da to 445431a Compare March 30, 2026 17:29
claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
@claygeo claygeo force-pushed the fix/deps-lock-write-permission-error branch from 445431a to 542393f Compare March 30, 2026 18:29
claygeo added a commit to claygeo/dbt-core that referenced this pull request Mar 30, 2026
@claygeo claygeo force-pushed the fix/deps-lock-write-permission-error branch from 542393f to b71ec6d Compare March 30, 2026 18:38
claygeo added 2 commits April 1, 2026 11:21
When dbt deps runs in a directory where the user lacks write
permissions (e.g. inside containers with read-only project mounts),
the lock file write fails silently. The user sees no error and no
packages are installed.

Wrap the lock file write in a try/except for OSError. On failure,
log a warning and proceed without the lock file, matching the
maintainer's preferred behavior from issue discussion (option 2:
handle and proceed).

The rest of dbt deps still works because load_yml_dict returns {}
for missing files, and the resolver falls back to packages.yml.

Fixes dbt-labs#9241
@claygeo claygeo force-pushed the fix/deps-lock-write-permission-error branch from b71ec6d to 958adb1 Compare April 1, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla:yes community This PR is from a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CT-3470] [Bug] dbt deps fails silently if user has no write perms to project directory

1 participant